Crawl Same-Hostname URLs Concurrently
Problem statement
Crawl the finite web graph described by pageUrls and linkLists, beginning at startUrl. The string linkLists[i] contains the absolute URLs returned when pageUrls[i] is parsed, separated by single spaces; an empty string means no links. A normalized URL absent from pageUrls has no outgoing links.
Before any comparison or lookup, remove the first # and everything after it. Visit only normalized URLs whose hostname exactly equals the normalized start URL's hostname. Different schemes may still have the same hostname. Never visit a normalized URL more than once, including through fragments or cycles.
Examples
Example 1
startUrl = "https://docs.acme.com/root#intro"pageUrls = ["https://docs.acme.com/root","https://docs.acme.com/a","https://docs.acme.com/b"]linkLists = ["https://docs.acme.com/a#one https://docs.acme.com/a#two https://other.com/out","https://docs.acme.com/b#part https://docs.acme.com/root#back","https://docs.acme.com/a"]workerCount = 4return = ["https://docs.acme.com/a","https://docs.acme.com/b","https://docs.acme.com/root"]Both fragments of /a normalize to one URL. The cycle through /root and /a cannot create another visit, and other.com is excluded.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.