The Maze
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Bloomberg OA reported in February 2021 gives you a 100 by 100 grid and a ball that won't stop rolling. Brute force over every path blows up fast, because the ball can revisit cells and loop forever. This is The Maze, a breadth-first search problem with one twist: nodes aren't every cell, they're only the cells where the ball comes to rest. If you see it as plain grid BFS, you'll get Example 2 wrong. If you blank on the rolling logic during the live assessment, StealthCoder is the safety net running invisibly on your screen.
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 is that a move isn't one step. From a stopping cell, you pick a direction and roll until the next cell is a wall or out of bounds. The cell where you halt is the neighbor. Run BFS or DFS over those stop points only, with a visited matrix so you never re-expand a stop. Return true when you pop the destination as a stop point. The common pitfall is checking the destination mid-roll. Example 2 exists to punish that: the ball passes through [3,2] but can't stop there. Another miss is forgetting to mark visited, which causes infinite loops. Complexity is O(m*n*(m+n)) since each stop point rolls up to four directions, each at most max(m,n) long. The outer walls make bounds checks simple. If the rolling loop feels shaky under the clock, StealthCoder can hand you the solution during the live OA.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
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 StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as the maze. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg 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 at Bloomberg?+
The ball doesn't move one cell at a time. It rolls until a wall blocks it. So your graph nodes are stopping positions only. Run BFS from the start, roll in all four directions, and enqueue each unvisited stop point. Return true if a stop point equals the destination.
Why does Example 2 return false?+
The ball can roll through [3,2] but never halts there. Reaching a cell mid-roll doesn't count. You only compare against the destination after a roll ends at a wall. Checking during the roll is the most common wrong answer on this problem.
BFS or DFS for this problem?+
Either works. Both visit each stop point once with a visited matrix. BFS with a queue is easier to write without recursion issues. With a 100 by 100 grid, recursive DFS depth is usually fine, but BFS avoids any stack worry. Pick what you can write fastest.
What's the time complexity, and does it pass the constraints?+
Each stop point is processed once, and each of its four rolls costs up to max(m,n) steps. That's roughly O(m*n*(m+n)). With both dimensions at most 100, that's a few million operations, which is comfortably fine.
How do I prepare for this in 48 hours?+
Write the roll loop by hand until it's automatic: step while the next cell is in bounds and equals 0, then stop. Then wrap it in BFS with a visited array. Test on both examples, especially the pass-through case. Two or three clean runs is enough.