Maze Flight Path

Backtracking Maze Grid Dfs Algorithm

Maze Flight Path

On December 17, 1903, the Wright brothers achieved the first controlled, sustained flight. In this problem, you will help navigate a grid maze representing the skies, where each cell is either open or blocked by obstacles. Your task is to find all possible flight paths from the top-left corner to the bottom-right corner of the maze using backtracking.

Problem Statement

Given a 2D grid (matrix) where:

  • 0 represents an open cell.
  • 1 represents a blocked cell.

Find all paths from the start position (0, 0) to the destination (m-1, n-1). Allowed moves are up, down, left, and right. A cell can only be visited once in each path.

Each valid path should be returned as a list of coordinates [row, column] representing the steps from start to finish.

Function Signature

Implement the function findMazePaths(grid) that returns a list of all valid paths. If no path exists, return an empty list.

Example:

Input:

grid = [
  [0, 0, 1],
  [0, 0, 0],
  [1, 0, 0]
]

One possible output (order of paths may vary):

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