The Maze III
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A ball sits in a grid maze where 0 is an empty cell and 1 is a wall; the area outside the grid also acts as a wall. The ball can be pushed 'u' (up), 'd' (down), 'l' (left) or 'r' (right). Once pushed, it keeps rolling through empty cells until the next cell in that direction is a wall, and then it stops. There is a hole in the maze: if the ball rolls **onto** the hole, it drops in immediately, even mid-roll.
Given maze, the ball's start ball = [row, col] and the hole hole = [row, col], return the sequence of pushes that gets the ball into the hole while traveling the **shortest distance**. Distance is the number of empty cells the ball passes through, counting the cell it ends on and not the start.
If several push sequences reach the hole with that same shortest distance, return the **lexicographically smallest** string among them. If the ball can never drop into the hole, return "impossible".
Examples
Constraints
- m == maze.length, n == maze[i].length
- 1 <= m, n <= 100
- maze[i][j] is 0 or 1
- `ball` and `hole` are empty cells and are different
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.