Reported September 2026
Googlebreadth first search

Shortest Land Path

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 detail that trips people on this Google OA, reported in September 2026, is the tie-break rule. Shortest path on a square grid of 0s and 1s is easy. Returning the lexicographically smallest coordinate sequence among equal-length paths is where candidates lose points. It's a BFS problem with a twist, and the twist is in how you rebuild the path. If you blank on the reconstruction, StealthCoder runs invisibly during the live OA and gives you a working solution as a safety net. Know the trick first and you won't need it.

The problem

Given a square binary grid, find a shortest path from start to target using only land. A cell containing 0 is land; a cell containing 1 is water.
Both endpoint arrays are zero-based coordinates [row, column]. A move travels one cell up, down, left or right, stays inside the grid, and never enters water. Each move has equal cost.
Return the path as an ordered array of coordinates, including the start and target. Minimize the number of moves. If several shortest paths exist, return the lexicographically smallest coordinate sequence: compare the first differing coordinates by row, then column.
Return an empty array when either endpoint is water or the target is unreachable. When the endpoints are the same land cell, return that one coordinate. Do not modify the grid or endpoint arrays.

Function
shortestLandPath(grid: int[][], start: int[], target: int[]) → int[][]

Examples
Example 1
grid = [[0,0,0],[1,1,0],[0,0,0]]
start = [0,0]
target = [2,0]
return = [[0,0],[0,1],[0,2],[1,2],[2,2],[2,1],[2,0]]
The only land route follows the top row, descends along column 2, then moves left along the bottom row. It uses 6 moves and includes both endpoints.
Example 2
grid = [[0,0],[0,0]]
start = [1,1]
target = [0,0]
return = [[1,1],[0,1],[0,0]]
Both shortest routes use 2 moves. The route through [0,1] wins because that first differing coordinate is lexicographically smaller than [1,0].
Example 3
grid = [[0,0,0],[1,1,1],[0,0,0]]
start = [0,0]
target = [2,2]
return = []
The water row separates the endpoints. No land-only route exists, so the result is an empty array.

Constraints
1 <= n == grid.length <= 40.
Every row contains exactly n cells, and every cell is 0 or 1.
start.length == target.length == 2; every coordinate is in 0..n-1.
A returned path has at most n^2 coordinates.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Run BFS from the target, not the start, and record each cell's distance to the target. Then walk forward from the start. At each step, look at the neighbors whose distance is exactly one less than the current cell's. Pick the smallest by row, then column. Because every shortest path is a chain of distance-decreasing steps, greedy choice at each step gives the lexicographically smallest sequence. The common pitfall is running BFS from the start and storing one parent per cell. That gives you some shortest path, not the smallest one. Other traps: forgetting that water endpoints return an empty array, and the same-cell case returning a single coordinate. With n up to 40, a grid of 1600 cells is trivial for BFS. If the pattern slips under pressure, StealthCoder is the hedge for the live OA.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Shortest Land Path 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 passed his OA cold and still thinks the filter is broken.

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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Shortest Land Path FAQ

What's the trick in Shortest Land Path?+

Do BFS from the target to get distances, then walk forward from the start. At each step, move to the neighbor with distance one less, choosing the smallest row, then smallest column. That guarantees the lexicographically smallest shortest path without comparing whole paths.

Why not just BFS from the start with parent pointers?+

Standard parent pointers record the first parent that discovers a cell. That yields one valid shortest path, but not necessarily the lexicographically smallest. You can try ordering neighbors cleverly, but the reverse BFS plus forward greedy walk is cleaner and easier to prove correct.

Which edge cases should I test before submitting?+

Test start or target on water, which returns an empty array. Test start equal to target on land, which returns one coordinate. Test an unreachable target, like a full water row. Also confirm you don't mutate the grid or the endpoint arrays, since the statement forbids it.

How hard is this Google OA question really?+

It's medium. The BFS itself is standard on a grid up to 40 by 40. The difficulty is the tie-break rule. If you've seen BFS with path reconstruction, the extra step is small. Candidates who miss it usually return a valid shortest path that isn't the smallest.

How do I prepare for this in 48 hours?+

Write grid BFS from memory with a four-direction array. Then practice the distance-map-then-greedy-walk reconstruction on two or three small grids by hand. Check your output against the three examples in the statement, especially the second one, which tests the tie-break.

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