Paths Around Rocks
grid holds 0 for an open cell and 1 for a rock. A hiker starts in the top-left cell and wants to reach the bottom-right cell, moving one cell right or one cell down at a time and never entering a rock. Return the number of different routes. If the start or the goal is a rock, or no route exists, return 0.
Example 1
grid [[0,0,0],[0,1,0],[0,0,0]]
returns 2
With the centre blocked, the hiker can go around it along the top and right edges or along the left and bottom edges.
Example 2
grid [[0,0],[0,0]]
returns 2
Right then down, or down then right.
Constraints
1 <= rows, cols <= 10grid[r][c]is 0 or 1
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Ramp DropMedium
- Settle the SandpileMedium
- Slide and MergeMedium
- Snake GameMedium
- Spiral FillMedium
- Spiral OrderMedium
- Spiral Out From a CellMedium
- Sudoku Rules CheckMedium