Reported September 2026
Googlebreadth first search

Choose a Shortest Path That Avoids Bob

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

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

The data structure that decides this Google OA question is a BFS queue, run twice over the same graph. Reported in September 2026, "Choose a Shortest Path That Avoids Bob" looks like a path puzzle, but it's really a distance comparison. Alice must pick a shortest path, Bob can wander anywhere, and capture means Bob gets to a node no later than she does. If you've done multi-source BFS before, you've seen the skeleton. If you blank on the setup, StealthCoder can run invisibly during the live OA as a safety net, but the idea is short enough to hold in your head tonight.

The problem

Alice and Bob move simultaneously along one edge per second in an undirected, unweighted graph. Alice must choose a shortest path from her start to the destination. Bob may choose any walk to catch her.
Return whether Alice can choose a shortest path such that Bob cannot occupy the same node at the same or an earlier time at any step, including the destination. Bob's earliest arrival time therefore determines safety.

Function
canAliceReachSafely(n: int, edges: int[][], aliceStart: int, bobStart: int, destination: int) → boolean

Examples
Example 1
n = 5
edges = [[0,1],[1,4],[0,2],[2,3],[3,4]]
aliceStart = 0
bobStart = 3
destination = 4
return = false
Alice takes 0-1-4; Bob reaches the destination too late.
Example 2
n = 4
edges = [[0,1],[1,3],[2,1]]
aliceStart = 0
bobStart = 2
destination = 3
return = false
Bob reaches the shared middle node before Alice.
Example 3
n = 3
edges = [[0,1],[1,2]]
aliceStart = 0
bobStart = 0
destination = 2
return = false
Bob starts on Alice, so capture is immediate.

Constraints
1 <= n <= 100000.
0 <= edges.length <= 200000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Run BFS from Alice's start to get distA, and BFS from Bob's start to get distB. Alice's shortest paths only use edges where distA increases by exactly 1 toward the destination. A node v on such a path is safe only if distA[v] < distB[v], since Bob arriving at the same time or earlier counts as capture. So restrict to nodes on shortest paths (distA[u] + distToDest[u] == distA[dest]) and check that a chain of safe nodes connects start to destination. A simple way: BFS or DP over the shortest-path DAG, only stepping into nodes where distA < distB. The pitfall is using less-than-or-equal instead of strict less-than, which flips example 3. Also handle unreachable destinations and watch recursion depth at n = 100000. If you freeze live, StealthCoder is the hedge, but the two-BFS idea is the whole trick.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Choose a Shortest Path That Avoids Bob 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Google reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Choose a Shortest Path That Avoids Bob FAQ

What's the core trick in this Google OA problem?+

Compute shortest distances from Alice and from Bob with two BFS runs. Then walk only along Alice's shortest-path edges and require distA[v] < distB[v] at every node, including the destination. Strict inequality matters because tying means Bob is there at the same time.

Why does Bob's earliest arrival time determine safety?+

Bob can walk anywhere and wait or loop, so if he can reach a node at time t, he can be there at any later time too. Alice is caught at a node if Bob's earliest arrival is at or before hers. So only distB[v] matters, not his actual route.

How hard is this really?+

Medium. The BFS is routine. The tricky part is restricting Alice to shortest-path edges only and handling the strict comparison. With n up to 100000 and 200000 edges, linear time BFS is required, and an iterative approach avoids stack issues.

What edge cases should I test?+

Bob starting on Alice's node, which is an immediate false as in example 3. Alice already at the destination. A destination that's unreachable. Disconnected graphs where Bob can't reach her path at all. Zero edges with n = 1. Test each against the strict less-than rule.

How do I prepare in 48 hours?+

Write BFS for distances from memory, then practice filtering a shortest-path DAG using distA[u] + 1 == distA[v]. Do one or two problems that combine two BFS passes. Then solve this one end to end and verify against the three given examples.

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

OA at Google?
Invisible during screen share
Get it