Reported September 2026
Waymodepth first search

Deterministic Depth-First Graph Traversal

Reported by candidates from Waymo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Waymo OA. Under 2s to a working solution.
Founder's read

The whole problem hinges on one thing: a visited set plus sorted adjacency lists. That's the Waymo OA reported in September 2026, a deterministic DFS on a directed graph with up to 100000 vertices. You return preorder, smallest neighbor first, and skip anything unreachable from start. It looks like a warmup, but the size limits and cycles punish the lazy version. If you've got an invite in your inbox, this is the shape to expect. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the idea is simple enough to write cold.

The problem

You are given a directed graph as adjacency, where vertices are numbered from 0 through adjacency.length - 1. The neighbors in each input list may appear in any order.
Starting at start, perform a depth-first traversal. Whenever a vertex has several unvisited outgoing neighbors, visit the neighbor with the smallest vertex number first.
Return the vertices in preorder: append a vertex when it is first discovered. Visit every reachable vertex exactly once and omit vertices that are unreachable from start.

Function
dfsTraversal(adjacency: int[][], start: int) → int[]

Examples
Example 1
adjacency = [[2,1],[3],[3],[1],[]]
start = 0
return = [0,1,3,2]
From 0, vertex 1 is chosen before 2. The traversal follows 1 to 3, then backtracks to visit 2. Vertex 4 is unreachable.
Example 2
adjacency = [[1],[2],[0,3],[]]
start = 2
return = [2,0,1,3]
At 2, neighbor 0 is explored before 3. The cycle back to 2 is ignored because 2 is already visited.
Example 3
adjacency = [[],[0],[1]]
start = 0
return = [0]
The start vertex has no outgoing edge, so the traversal contains only that vertex.

Constraints
1 <= adjacency.length <= 100000.
0 <= start < adjacency.length.
Every neighbor is a valid vertex, every directed edge appears at most once, and the graph may contain cycles or self-loops.
The total number of directed edges is at most 200000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is sorting each neighbor list ascending before you traverse, because input order is arbitrary. Then run DFS from start, mark a vertex visited the moment you discover it, and append it to the result at that point. That's preorder. Sorting costs O(E log E) total, which is fine for 200000 edges. The big pitfall is recursion depth. A path graph with 100000 vertices will blow the stack in many languages, so use an explicit stack. If you do, push neighbors in descending order so the smallest pops first, and check visited again on pop, since a vertex can be pushed twice. Self-loops and cycles are handled by the visited check. If you freeze on the iterative version in the live OA, StealthCoder is the hedge that gets you a working stack-based solution fast.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Deterministic Depth-First Graph Traversal cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Waymo's OA.

Waymo reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Deterministic Depth-First Graph Traversal FAQ

How hard is the Waymo deterministic DFS question really?+

Easy to medium. The algorithm is textbook DFS. The difficulty is in the details: sorting neighbors, preorder timing, and avoiding stack overflow on 100000 vertices. If you've written iterative DFS before, it's a ten minute problem.

What's the trick to getting the order right?+

Sort each adjacency list ascending, then visit in that order. Append a vertex to the result when you first discover it, not when you finish it. Example 1 shows this: 0, then 1, then 3, then back to 2.

Should I use recursion or an explicit stack?+

Use an explicit stack. With up to 100000 vertices, a long chain can overflow the call stack. Push neighbors in descending order so the smallest comes off first, and re-check visited when you pop to avoid duplicates.

How do cycles and self-loops affect the answer?+

They don't, as long as you track visited. Example 2 has a cycle back to the start and it's ignored because the start is already visited. A self-loop is just a neighbor that's already visited the moment you see it.

How do I prepare for this in 48 hours?+

Write iterative DFS from memory twice, once with a preorder list and once with sorted neighbors. Test on a chain, a cycle, and a single isolated start vertex. Those three cases cover the traps in this problem.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Waymo.

OA at Waymo?
Invisible during screen share
Get it