The Maze

Understand and solve the interview question "The Maze".

We'll cover the following

Description

The maze is a puzzle game where the ball moves in the available empty spaces. The player aims to get the ball to the specified destination. The ball can go through the empty spaces by rolling up, down, left, or right, but it will not stop rolling until it hits a wall or reaches the destination and then hits a wall or reaches the end of a grid. After hitting a wall, the ball will choose the next direction before moving forward. The borders of the maze are considered walls.

Constraints

• maze[i][j] must be 0 or 1, initially.
• maze_length == maze.length
• maze_subarray_length == maze[i].length
• 1 <= maze_length, maze_subarray_length <= 100
• start.length, end.length == 2
• 0 <= $start_{row}$, $end_{row}$ <= mazeLength
• 0 <= $start_{col}$, $end_{col}$ <= maze_subarray_length
• The ball and the destination must exist in an empty space and, initially, they will not be in the same position.
• The maze must contain at least two empty spaces.

Let’s see how the maze game looks in the illustration below:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.