Four-Direction Unique Grid Paths
Problem statement
In a binary grid, 1 is passable and 0 blocked. Return every simple path from the start cell to the end cell using Down, Left, Right, or Up moves. A simple path visits no cell more than once.
Encode paths with letters D, L, R, U and return them lexicographically.
Function
allGridPaths(grid: int[][], startRow: int, startCol: int, endRow: int, endCol: int) → String[]Examples
Example 1
grid = [[1,1],[1,1]]startRow = 0startCol = 0endRow = 1endCol = 1return = ["DR","RD"]The two simple shortest paths use Down-Right and Right-Down.
Constraints
- At most 16 cells are passable.
- Start and end are valid grid coordinates.