MEDIUMasked at 1 company

The Maze II

A medium-tier problem at 54% community acceptance, tagged with Array, Depth-First Search, Breadth-First Search. Reported in interviews at Uber and 0 others.

Founder's read

The Maze II is the harder cousin of the classic maze problem, and Uber has asked it. You're given a ball rolling on a 2D grid that can't stop mid-slide, only at walls or boundaries. Instead of just finding if you can reach the exit, you now have to find the shortest path there. Acceptance hovers around 54 percent, meaning most candidates either miss the shortest-path constraint or build an inefficient search. If this hits your live OA and you blank on why BFS plus distance tracking fails here, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
54%

Companies that ask "The Maze II"

If this hits your live OA

The Maze II is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.

Get StealthCoder
What this means

The trap is thinking standard BFS is enough. Since the ball slides until it hits a wall, each step isn't one grid cell, it's a whole trajectory. You need to track the distance traveled to each position, not just whether you've visited it, because you can reach the same cell via different path lengths. Dijkstra's algorithm with a heap becomes the real solution: process cells in order of increasing distance, so the first time you pop a cell from the priority queue, you know you've found its shortest path. Most candidates either implement basic BFS which gets the wrong answer, or they get stuck on how to model the rolling mechanic correctly. The graph here is implicit in the grid structure and rolling rules, not pre-built. StealthCoder hedges the moment you realize you're rewriting BFS three times on the whiteboard.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

The Maze II recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.

The Maze II interview FAQ

Why doesn't standard BFS work for this problem?+

BFS finds shortest path in unweighted graphs by visit count. Here, moving one 'step' (rolling until you hit a wall) can cover variable distance. You need shortest distance, not fewest rolls. That's why Dijkstra's algorithm with a heap, which respects variable edge weights, is the correct approach.

What's the actual trick to modeling the ball's movement?+

Simulate rolling in all four directions from each position. For each direction, keep rolling until you hit a wall or boundary, then record the final position and total distance traveled. This builds your graph on the fly. The key is tracking distance as the edge weight, not the number of moves.

Is this still asked frequently at Uber and similar companies?+

Uber has confirmed asking it. It's a medium-difficulty graph problem that tests both pathfinding algorithm knowledge and the ability to model a non-standard grid mechanic. It's less common than basic BFS but appears in their coding rounds.

How does Heap or Priority Queue relate to this problem?+

Dijkstra's algorithm uses a min-heap to always process the unvisited cell with the smallest distance next. This guarantees that when you pop a cell, you've found the shortest path to it. Without a heap, you'd process cells inefficiently and potentially miss the optimal solution.

What's the common pitfall after implementing the rolling mechanic?+

Getting the distance update logic wrong. Candidates often treat 'visited' as a boolean when it should track the best distance seen so far to each cell. You can visit the same cell multiple times if a new path has shorter distance. Only a heap-based approach handles this correctly.

Want the actual problem statement? View "The Maze II" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.