Java Solution using Dynamic Programming, O(1) space
public class Solution {\n        public int uniquePathsWithObstacles(int[][] obstacleGrid) {\n            \n            //Empty case\n            if(obstacleGri
    public class Solution {\n        public int uniquePathsWithObstacles(int[][] obstacleGrid) {\n            \n            //Empty case\n            if(obstacleGrid.length == 0) return 0;\n            \n            int rows = obstacleGrid.length;\n            int cols = obstacleGrid[0].length;\n            \n            for(int i = 0; i < rows; i++){\n                for(int j = 0; j < cols; j++){\n                    if(obstacleGrid[i][j] == 1)\n                        obstacleGrid[i][j] = 0;\n                    else if(i == 0 && j == 0)\n                        obstacleGrid[i][j] = 1;\n                    else if(i == 0)\n                        obstacleGrid[i][j] = obstacleGrid[i][j - 1] * 1;// For row 0, if there are no paths to left cell, then its 0,else 1\n                    else if(j == 0)\n                        obstacleGrid[i][j] = obstacleGrid[i - 1][j] * 1;// For col 0, if there are no paths to upper cell, then its 0,else 1\n                    else\n                        obstacleGrid[i][j] = obstacleGrid[i - 1][j] + obstacleGrid[i][j - 1];\n                }\n            }\n            \n            return obstacleGrid[rows - 1][cols - 1];\n            \n        }\n    }
[]