Reported September 2026
Goldman Sachsbreadth first search

The Maze

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

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

Goldman Sachs reportedly put The Maze in front of candidates in September 2026, and the trap is one word: stop. The ball doesn't move one cell at a time. It rolls until a wall blocks it, and passing through the destination doesn't count. If you've got an OA coming, this is a BFS (or DFS) over stopping points, not over every cell. Most people write a normal grid search and fail Example 2 on the spot. If you blank on the rolling logic during the live assessment, StealthCoder is the invisible safety net that reads the problem and hands you a working solution.

The problem

A ball is placed in a rectangular maze represented by a binary matrix. Empty cells contain 0 and walls contain 1. The ball can move up, down, left, or right, but it keeps rolling in the chosen direction until a wall stops it.
Given the ball's start and destination cells, return true if the ball can stop at the destination and false otherwise.

Function
hasPath(maze: int[][], start: int[], destination: int[]) → boolean

Examples
Example 1
maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]]
start = [0,4]
destination = [4,4]
return = true
A sequence of rolls can stop the ball at the destination.
Example 2
maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]]
start = [0,4]
destination = [3,2]
return = false
The ball can pass through the destination cell but cannot stop there.

Constraints
1 <= maze.length, maze[0].length <= 100
maze[i][j] is either 0 or 1.
start and destination each contain two coordinates.
The start and destination cells are empty.
The maze is surrounded by walls outside its boundary.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: treat only cells where the ball comes to rest as graph nodes. From each node, try all four directions, keep moving while the next cell is inside the grid and equals 0, then record the final cell. Push it into a queue if you haven't visited it. Return true only when a popped stopping cell equals the destination. The common pitfall is checking the destination during the roll, which wrongly returns true for Example 2, where the ball slides through [3,2] but never stops. Another bug is marking every traversed cell visited instead of just stopping cells, which blocks valid paths. Complexity is O(m*n*(m+n)) worst case, fine for 100x100. If the rolling loop or the visited logic slips under pressure, StealthCoder can cover you during the live OA.

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 The Maze 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

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as the maze. If you have time before the OA, drill that.

⏵ The honest play

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

Goldman Sachs 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.

The Maze FAQ

What's the trick in The Maze problem?+

Nodes are stopping positions, not every cell. From a stop, roll in each of four directions until the next cell is a wall or out of bounds, then enqueue that resting cell. Only a resting cell matching the destination counts as success.

Why does Example 2 return false?+

The ball can roll through [3,2] but nothing stops it there, since continuing in that direction is still open. The destination must be a resting point. That's why you check equality after the roll finishes, not during it.

Should I use BFS or DFS for this?+

Either works. Both explore reachable stopping points with a visited set. BFS with a queue is easy to write iteratively and avoids recursion depth worries on a 100x100 grid. Pick whichever you can code without bugs under time pressure.

What edge cases break a naive solution?+

Checking the destination mid-roll, marking all passed cells visited, and forgetting that start can equal destination. Also watch bounds: the maze is described as walled outside, but your loop should still check indices before reading a cell.

How do I prepare for this in 48 hours?+

Write the roll-until-wall helper once, then wrap it in a BFS with a visited matrix. Test it on both examples, especially the false one. Then try a variant that returns shortest distance, since it uses the same skeleton with a priority queue.

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

OA at Goldman Sachs?
Invisible during screen share
Get it