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:
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.
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)
.
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!