Crawl Reachable Pages with Bounded Retries
Updated
Problem statement
A crawler starts at page start in a finite directed graph. Pages have integer IDs from 0 through initialFailures.length - 1. Each row [from, to] in links represents an outgoing link from one page to another.
A successful request for a page reveals all of its outgoing links. A failed request reveals no links. For page v, the first initialFailures[v] requests fail; every later request succeeds. The graph and this failure pattern remain fixed during the crawl.
- Discover the starting page first. A successful fetch discovers every page named by its outgoing links.
- For each discovered page, make one initial request and at most
maxRetriesadditional requests after failures. Stop requesting that page after its first success or after allmaxRetries + 1requests have failed. - Keep one shared record of discovered pages. Process each page only once, even if several links lead to it. Finding another link to a page does not give it more retries.
- Follow a page’s outgoing links only after a successful request. A page whose requests all fail is different from a page that succeeds but has no outgoing links.
- Links are directed. Duplicate links, self-links and cycles are allowed.
Return the IDs of all successfully fetched pages in ascending order. A discovered page whose requests all fail is excluded. If every allowed request for the starting page fails, return an empty array.
The input simulates an API with fixed results. Do not make real network requests. Processing pending pages in a different order does not change which page IDs you return.
Discussion follow-up
Describe how to use a bounded worker pool for the same crawl. Discovery and the claim to process a page must be atomic, the retry budget must belong to that page rather than an incoming link, and completion must wait until both pending and in-flight work are empty. Explain how these rules prevent duplicate dispatch and premature termination. The judged function uses the finite simulator above and does not create threads.
Function
crawlReachablePages(links: int[][], initialFailures: int[], start: int, maxRetries: int) → int[]Examples
Example 1
links = [[0,1],[0,2],[1,3],[2,3]]initialFailures = [0,1,3,0]start = 0maxRetries = 1return = [0,1,3]Page 0 succeeds immediately. Page 1 succeeds on its retry and reveals page 3, which also succeeds. Page 2 exhausts two requests, so it is excluded. The result is [0,1,3].
Example 2
links = [[0,1],[1,2],[2,0]]initialFailures = [2,0,0]start = 0maxRetries = 1return = []Both permitted requests for page 0 fail. Its outgoing link is never revealed, so the result is empty.
Example 3
links = [[2,1],[1,0],[0,2]]initialFailures = [1,0,2]start = 2maxRetries = 2return = [0,1,2]Starting at page 2, the final allowed request succeeds after two failures. The cycle reaches pages 1 and 0; global discovery prevents repeated processing. Return [0,1,2] in ascending order.
Constraints
1 <= initialFailures.length <= 200.0 <= links.length <= 2000. Each link has exactly two valid page IDs.0 <= initialFailures[v] <= 6for every pagev.0 <= maxRetries <= 5.startis a valid page ID.
More Snowflake Phone Screen questions
- Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
- Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
- Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
- Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
- Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
- Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
- Greedy Person-Cake Matching DistancePHONE SCREEN · Seen Nov 2026
- Tree Height After Child PromotionPHONE SCREEN · Seen Oct 2026
- Minimum StackPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Breadth-First Order of a GraphAdobe · PHONE SCREENAdobe interview questions
- Distances to CyclesBelvedere Trading · OA
- Cogwheel Rotation DirectionsOpenAI · OAOpenAI interview questions
- Shortest Path in an Unweighted GraphCitadel · OACitadel interview questions
- Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- 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