FastPrepWeb Crawler Shortest Path Reconstruction
Problems/Web Crawler Shortest Path Reconstruction

Web Crawler Shortest Path Reconstruction

Snowflake logoSnowflake● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Snowflake phone screen. The report separates returning a shortest page path from returning only the fewest clicks, and asks for backtracking that saves space. We supply a finite snapshot of links that were found, page names, ties broken in alphabetical order, directed cycles and how unreachable pages work. We do not simulate network failures. Our version is about 95% the same as the reported question.

A crawler has a complete, finite snapshot of the outgoing links between the distinct page names in pages. Each row [from, to] in links is a directed link. Following one link costs one click.

Return a shortest path from start to target as an array of page names, including both endpoints. Minimize the number of links used. If several paths use that minimum number, return the lexicographically smallest sequence of page names: compare the first unequal names using ordinary lowercase string order, with a proper prefix smaller than its extension.

  • If start == target, return [start], even when that page has no links.
  • If the target cannot be reached, return an empty array.
  • Links are directed; do not add reverse links. Cycles and self-links are allowed.
  • The order of pages and input link rows does not determine the answer.

The snapshot stands for a link-finding service that always works: a page’s outgoing links are exactly the rows whose first entry names that page. There are no network calls, failures or retries in the input.

For the space follow-up, store one predecessor per discovered page and rebuild the path afterward, instead of carrying a full path with each queued page.

Function

shortestPagePath(pages: String[], links: String[][], start: String, target: String) → String[]

Examples

Example 1

pages = ["home","beta","alpha","goal"]links = [["home","beta"],["beta","goal"],["home","alpha"],["alpha","goal"]]start = "home"target = "goal"return = ["home","alpha","goal"]

Both routes use two clicks. The route through alpha is lexicographically smaller even though beta's links appear first.

Example 2

pages = ["start","mid","end","island"]links = [["start","mid"],["mid","start"],["mid","end"]]start = "end"target = "start"return = []

Links are directed. The cycle from start through mid does not provide any outgoing route from end back to start.

Constraints

  • 1 <= pages.length <= 100.
  • Every page name is unique, contains only lowercase English letters and has length from 1 through 10.
  • 0 <= links.length <= 200; each row contains exactly two names from pages. No directed link is repeated.
  • start and target are members of pages.

More Snowflake Phone Screen questions

  • Minimum StackPHONE SCREEN · Seen Nov 2026
  • Design In-Memory File SystemPHONE SCREEN · Seen Nov 2026
  • Merge Two Binary TreesPHONE SCREEN · Seen Nov 2026
  • 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

Similar questions at other companies

  • Detonate the Maximum BombsZomato / Eternal · PHONE SCREENZomato / Eternal interview questions
  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
  • Course ScheduleByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • Merge Accounts by Shared AttributeAmazon · PHONE SCREEN
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Shortest Pin Path Through TopicsPinterest · PHONE SCREENPinterest interview questions
  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
  • Evaluate DivisionApple · PHONE SCREENApple interview questions

Snowflake interview experiences

  • Snowflake AI Coding Interview, Experienced Hires: 3 Experiences
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public String[] shortestPagePath(String[] pages, String[][] links, String start, String target) {
        // Write your code here
    }
}
Checking account…