Overview
This is a variation of "Unique Paths". The core logic remains the same: the number of ways to reach a cell is the sum of ways to reach the cell above it and the cell to its left.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Find the number of unique paths from the top-left to the bottom-right of a grid, but this time, the grid contains obstacles that block your path.
This is a variation of "Unique Paths". The core logic remains the same: the number of ways to reach a cell is the sum of ways to reach the cell above it and the cell to its left.
If a cell contains an obstacle (represented by `1`), you cannot step on it. Therefore, the number of ways to reach that specific cell is `0`.
When initializing the first row and column, if you hit an obstacle, all subsequent cells in that row/column must be `0` because they are permanently blocked.
Just like Unique Paths, this can be optimized to `O(N)` space by only keeping track of the current row and the previous row, or even just a single 1D array.