Unique Paths II
A robot starts at the top-left of an m x n grid and moves only right or down to reach the bottom-right. Some cells contain obstacles marked 1 (empty cells are 0), which the robot cannot enter. Return the number of distinct obstacle-free paths.
Open official problem prompt ↗We want to count right/down paths across the grid while never stepping on a blocked cell.
Water flowing downhill and rightward through a grid of pipes where obstacle cells are plugged, so flow reroutes around them.
- Input
- obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]
- Output
- 2
- Why
- The single obstacle in the center leaves exactly two ways around it: right-right-down-down and down-down-right-right.
m == obstacleGrid.lengthn == obstacleGrid[i].length1 <= m, n <= 100obstacleGrid[i][j] is 0 or 1.