A website stores every page visit in its logs. Each log entry has the visited url and its referrer, which is the page the visitor came from. A referrer of "-" means the page was opened directly, without a referrer.
Every log entry with a referrer creates a one-way link from referrer to url. URL a is linked to URL b if b can be reached from a by following one or more of these links.
Implement the UrlLinkChecker class to check whether two URLs are linked through the referrer logs.
UrlLinkChecker(List<String> logs)
logs is in the format "url,referrer".logs may contain repeated entries, self links and cycles.boolean areURLsLinked(String a, String b)
true if b can be reached from a by following one or more links, otherwise returns false./x to /y does not link /y to /x.logs has no links.1 ≤ logs.size() ≤ 10,000logs is in the format "url,referrer".1 ≤ length of every URL ≤ 50'/' and contains only lowercase English letters, digits, '/', '.' and '-'.referrer is either "-" or a URL in the same format.a and b are URLs in the same format and a ≠ b.1,000 calls will be made to areURLsLinked.UrlLinkChecker checker = new UrlLinkChecker(logs = ["/home,-", "/menu,/home", "/menu,/home", "/order,/menu", "/home,/order", "/faq,-", "/contact,/faq"])
Links created: /home → /menu, /menu → /order, /order → /home, /faq → /contact. The repeated entry creates the same link again, and entries with referrer "-" create no link.
checker.areURLsLinked(a = "/home", b = "/order") returns true, path: /home → /menu → /order.checker.areURLsLinked(a = "/order", b = "/menu") returns true, path: /order → /home → /menu.checker.areURLsLinked(a = "/contact", b = "/faq") returns false, links are one-way and /contact has no outgoing link.checker.areURLsLinked(a = "/menu", b = "/faq") returns false, starting from /menu only /order, /home and /menu can be reached.UrlLinkChecker checker = new UrlLinkChecker(logs = ["/blog,/blog", "/blog/post-1,/blog", "/blog/post-2,/blog/post-1", "/rss.xml,-"])
Links created: /blog → /blog, /blog → /blog/post-1, /blog/post-1 → /blog/post-2.
checker.areURLsLinked(a = "/blog", b = "/blog/post-2") returns true, path: /blog → /blog/post-1 → /blog/post-2.checker.areURLsLinked(a = "/blog/post-2", b = "/blog") returns false, /blog/post-2 has no outgoing link.checker.areURLsLinked(a = "/blog", b = "/rss.xml") returns false, /rss.xml was only opened directly, so no link leads to it.checker.areURLsLinked(a = "/login", b = "/blog") returns false, /login does not appear in logs.