Texas Maze Escape

Backtracking Maze Grid Texas Independence Day

Texas Maze Escape

In honor of Texas Independence Day on March 2, imagine a pioneer trying to find a way through a maze to secure freedom. You are given a 2D grid representing a maze where:

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

Your task is to find all possible paths from the top-left cell (start) to the bottom-right cell (exit) using backtracking. You can move in four directions: up, down, left, and right. You cannot move outside the grid or enter a blocked cell, and you should not revisit any cell in a single path.

Input

  • A 2D grid (list of lists or equivalent) of integers (0s and 1s).

Output

  • A list of paths, where each path is represented as a sequence of coordinates (row, column) that outlines the steps from the start cell to the exit cell.

Example

Given the maze:

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

One possible path could be: (0,0) -> (0,1) -> (1,1) -> (1,2) -> (2,2).

Starter Code

Below is some language-agnostic starter code to help you begin your solution implementation using backtracking:

// Function: findPaths
// Input: grid - a 2D array of integers (0s for open cells, 1s for blocked cells)
// Output: an array (or list) of paths, where each path is a sequence of coordinates (row, col)

Implement your solution using recursion and backtracking. Good luck and happy coding on this Texas Independence Day challenge!