You are given a 2D grid maze represented by a matrix where:
0
represents an open cell where you can move.1
represents a wall where you cannot move.Your task is to determine if there exists a path from the top-left corner (start) to the bottom-right corner (end) using backtracking. You can only move up, down, left, or right (no diagonal moves). If a path exists, return it as a list (or array) of coordinates; if no valid path exists, return an empty list (or array).
0
and 1
).[row, col]
or similar) representing one valid path from the start to the finish. If no path exists, return an empty list.For the following maze:
[[0, 0, 1, 0],
[1, 0, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]]
One possible valid path from (0,0)
to (3,3)
could be:
[(0, 0), (0, 1), (1, 1), (1, 2), (1, 3), (2, 3), (3, 3)]
Happy coding!