Given a grid with blocked cells, return the number of valid right/down paths from the top-left to the bottom-right cell using a space-optimized DP approach. Pattern focus: Space optimization. This is the rolling-array version of obstacle-aware path counting.
grid contains 0 for free cells and 1 for blocked cells
number of valid paths
Example 1:
Input:
grid = [[0,0,0],[0,1,0],[0,0,0]]
Output:
2
Explanation:
The blocked center leaves 2 valid routes.
Example 2:
Input:
grid = [[0,0,0],[0,0,0],[0,0,0]]
Output:
6
Explanation:
An open 3x3 grid has 6 ways.
Example 3:
Input:
grid = [[0,1,0],[0,0,0],[0,0,0]]
Output:
3
Explanation:
One obstacle reduces the total to 3.