Given a 2D maze represented by a matrix, where 1
represents an open cell and 0
represents an obstacle, write a function to find all possible paths from the top-left cell (start) to the bottom-right cell (finish). You can move in four directions: up (U
), down (D
), left (L
), and right (R
).
(0, 0)
and end at position (M-1, N-1)
.1
(open cells). Moving to a cell with 0
is not allowed.U
, D
, L
, and R
.For the maze:
1 0 0
1 1 0
0 1 1
One valid path (if it exists) could be: DDRDR
which corresponds to Down, Down, Right, Down, Right.
Get started by implementing a function that performs backtracking to explore all valid paths.