Navigate a Binary Grid with Obstacle Jumps
Problem statement
A rectangular binary grid contains walkable cells 1 and blocked cells 0. Determine whether you can travel from the top-left cell to the bottom-right cell.
A move is either a one-cell step up, down, left or right onto a 1, or a two-cell jump in one of those directions whose intermediate cell is 0 and whose landing cell is 1. Both the intermediate and landing cells must lie inside the grid. Diagonal moves and jumps over a 1 are not allowed.
For this exercise, assume jumps may be repeated any number of times and do not change the grid. There is no obstacle-removal budget. If either endpoint is blocked, return false. A single walkable cell is already reachable. Return true exactly when some sequence of legal moves reaches the bottom-right cell.
Function
canNavigateGrid(grid: int[][]) → booleanExamples
Example 1
grid = [[1,0,1],[0,0,0],[1,0,1]]return = trueJump right over the top-middle obstacle, then down over the middle-right obstacle.
Example 2
grid = [[1,0,0,1]]return = falseTwo consecutive blocked cells cannot be crossed by a jump over exactly one obstacle.
Example 3
grid = [[1]]return = trueThe start is already the destination.
Constraints
1 <= grid.length, grid[0].length <= 30.- Every row has the same length and every entry is
0or1.