Reported September 2026
Googlebreadth first search

Shortest Path Node Count Avoiding Broken Nodes

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 queue is the whole answer here. Google's September 2026 report is a shortest path node count on a directed graph with broken nodes you can't touch. It's BFS on an unweighted graph with one extra rule: skip anything in the broken set. Every edge costs the same, so the first time you reach the destination is the minimum. You have an OA coming and you need the pattern, not a lecture. This is a standard graph traversal with two edge cases that bite people who rush. If you blank on the day, StealthCoder runs invisibly on your screen and gives you the working solution as a hedge.

The problem

You are given a directed graph as an adjacency list, a list of broken node indices, a start node, and a destination node. Return the minimum number of nodes on a directed path from start to destination that never visits a broken node. Count both endpoints.
Return -1 when no valid path exists. If start equals destination and that node is not broken, return 1. If either endpoint is broken, return -1.

Function
minimumPathNodeCount(graph: int[][], broken: int[], start: int, destination: int) → int

Examples
Example 1
graph = [[1,2],[3],[4],[4],[]]
broken = [1]
start = 0
destination = 4
return = 3
The shorter route uses broken node 1, so the valid path is 0 to 2 to 4 and contains three nodes.
Example 2
graph = [[1],[],[3],[]]
broken = []
start = 0
destination = 3
return = -1
The destination is unreachable in the directed graph.

Constraints
1 <= graph.length <= 200000
Every neighbor is a valid node index; the total edge count is at most 300000.
broken contains unique valid node indices.
0 <= start, destination < graph.length

Reported by candidates. Source: FastPrep

Pattern and pitfall

Put the broken indices into a boolean array or a set. Check the endpoints first: if start or destination is broken, return -1. If start equals destination and it's fine, return 1. Then run BFS from start with a queue, tracking distance as node count, so start begins at 1. Mark nodes visited when you push them, not when you pop them. Skip any neighbor that's broken or already seen. Return the count the moment you pop or push the destination. If the queue empties, return -1. The common pitfall is counting edges instead of nodes, which is off by one. Another is using DFS, which doesn't give the shortest path. With up to 200000 nodes and 300000 edges, you need O(V+E), and a list-based queue with pop(0) will be too slow. Use a deque or an index pointer. StealthCoder is the safety net if the edge cases slip your mind live.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Shortest Path Node Count Avoiding Broken Nodes 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Shortest Path Node Count Avoiding Broken Nodes FAQ

What's the trick in the Google shortest path with broken nodes problem?+

Use BFS, not DFS. Every edge has equal cost, so BFS finds the fewest nodes first. Treat broken nodes as already visited so the search never enters them. Check both endpoints for broken status before you start, because that returns -1 immediately.

Do I count nodes or edges in the answer?+

Nodes, and both endpoints count. Start the distance at 1 for the start node. In Example 1 the path 0 to 2 to 4 has three nodes, so the answer is 3. If start equals destination and isn't broken, the answer is 1.

What edge cases should I test before submitting?+

Test start broken, destination broken, start equal to destination, and an unreachable destination. Also try an empty broken list and a graph where the shortest route is blocked, so the longer route wins. Those cases cover most wrong answers on this problem.

Will a slow queue fail the large inputs?+

Yes, it can. With 200000 nodes and 300000 edges, you need O(V+E). Use a deque, or an array with a head pointer. Popping from the front of a plain list costs O(n) each time and can push you into a timeout.

How do I prepare for this in 48 hours?+

Write BFS on an adjacency list from memory twice. Add a visited array and a blocked set. Then practice the distance-as-node-count version and the early returns for broken endpoints. That's enough for this pattern, since the code is short once you've typed it a couple of times.

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