Maze Path Finder

Backtracking Maze Path Finding Algorithm

Maze Path Finder

In this challenge, you are given a maze represented by a 2D grid. Each cell in the grid contains either a 0 (indicating a free space) or a 1 (indicating a wall). Your task is to find a path from the top-left corner (start) to the bottom-right corner (finish) using backtracking. You can move up, down, left, or right. If no valid path exists, return an empty list.

Problem Details

  • The maze is provided as a 2D array (list of lists) where 0 represents a free cell and 1 represents a block.
  • Start is at position [0, 0] and finish is at position [n-1, m-1] (n being the number of rows and m being the number of columns).
  • You may only move in four directions: up, down, left, or right.
  • You cannot visit the same cell twice in a single path.

Example

For the following maze:

[[0, 0, 1],
 [1, 0, 0],
 [1, 1, 0]]

A valid path (if one exists) might be:

[(0,0), (0,1), (1,1), (1,2), (2,2)]

Starter Code

Below is some language-agnostic starter code to help you get started.

  • Function Signature: solveMaze(maze)
  • Input: A 2D array representing the maze.
  • Output: An array/list of coordinates (e.g., tuples or arrays) where each coordinate is in the format (row, col) representing the path from start to finish. Return an empty list if no path exists.

Happy coding and enjoy the spirit of problem solving this season!