Search⌘ K
AI Features

The Maze

Explore how to implement a maze puzzle solver using depth-first search in Rust. Understand how to traverse a grid by rolling the ball until hitting a wall, tracking visited cells, and using recursion to reach the destination. This lesson helps you apply algorithmic thinking and DFS techniques to solve grid-based pathfinding challenges.

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.
  • mazeLength == maze.length
  • mazeSubarrayLength == maze[i].length
  • 1 <= mazeLength, mazeSubarrayLength <= 100
  • start.length, end.length == 2
  • 0 <= startrowstart_{row}, endrowend_{row}
...