You are given an m x n integer grid obstacleGrid where 0 marks an empty cell and 1 marks an obstacle. Starting from the top-left cell, return the number of distinct paths to the bottom-right cell, moving only right or down and never stepping onto an obstacle.
If the start or the destination cell is an obstacle, there are 0 valid paths.
Input / output
obstacleGrid: int[][]int (number of obstacle-free paths)Examples
obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]] returns 2; the single middle obstacle leaves two ways around it.obstacleGrid = [[0,1],[0,0]] returns 1.obstacleGrid = [[1]] returns 0 because the start itself is blocked.Constraints
1 <= m, n <= 100obstacleGrid[i][j] is 0 or 1Follow-up
The full grid of subresults is easy to write but uses O(m*n) memory. Can you compute the answer with only O(n) extra space by reusing a single row?