Concurrent Web Crawler Reachability
Updated
Problem statement
A production crawler fetches many discovered pages concurrently while ensuring that each known page is fetched at most once.
In this practice version, pages[i] identifies a known page and outgoing[i] contains the links found after fetching it. Starting at startUrl, return every reachable known page in lexicographic order. Ignore links that do not occur in pages.
The result must be independent of worker completion order. As a discussion point, explain how an atomic visited set and a size-limited worker queue prevent duplicate fetches and too many fetches at once.
Function
crawlReachable(startUrl: String, pages: String[], outgoing: String[][]) → String[]Examples
Example 1
startUrl = "a"pages = ["a","b","c","d"]outgoing = [["b","c"],["d"],["d"],[]]return = ["a","b","c","d"]Both branches reach d, but it is returned once.
Example 2
startUrl = "home"pages = ["home","about","orphan"]outgoing = [["about","external"],[],["home"]]return = ["about","home"]Unknown external is ignored and orphan is not reachable.
Example 3
startUrl = "solo"pages = ["solo"]outgoing = [["solo"]]return = ["solo"]A self-link does not duplicate the page.
Constraints
1 <= pages.length == outgoing.length <= 100000.- Page identifiers are unique non-empty strings, and
startUrloccurs inpages. - The total number of links is at most
300000.
More Temporal interview questions
Similar questions at other companies
- Crawl Same-Hostname URLs ConcurrentlyAnthropic · PHONE SCREENAnthropic interview questions
- Concurrent Web Crawler SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Shortest Pin Path Through TopicsPinterest · PHONE SCREENPinterest interview questions
- Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
- Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Evaluate DivisionApple · PHONE SCREENApple interview questions
- Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
- Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions