Can a Rolling Ball Stop on the Exit of a Tilt Maze
Last updated: November 29, 2026
Quick Overview
In a maze grid of 0 (open) and 1 (wall), a ball rolls in one of four directions and keeps going until it hits a wall; given a start and a destination, return whether the ball can stop exactly at the destination.
0
0
0 solved
In a maze grid of 0 (open) and 1 (wall), a ball rolls in one of four directions and keeps going until it hits a wall; given a start and a destination, return whether the ball can stop exactly at the destination.
A Google onsite graph-modeling problem: the key twist is that nodes are stopping points, not every cell. The interviewer checks that you redefine the neighbors correctly and do not mark cells you only roll through as visited.
What the Interviewer Expects
- Models states as stopping cells only
- Generates neighbors by rolling until the next cell is a wall or out of bounds
- Uses BFS or DFS with a visited set on stopping cells
- Recognizes that passing over the destination does not count
- States O(mn(m + n)) time in the worst case
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the shortest distance in cells rolled (weighted edges).
- Return the lexicographically smallest direction string to drop into a hole that the ball can pass over.
- Precompute roll destinations to make each neighbor lookup O(1).
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
mazem x n of 0/1,startanddestare open cells.- The ball stops only when the next cell is a wall or the boundary.
- Output:
Trueifdestcan be a stopping point....
High-Level Design
Each stopping cell is a node. From a node, simulate rolling in each direction until the next step is blocked; the final cell is a neighbor. BFS over these nodes. Rolling through the destination withou...