Beats 90.79%  63. Unique Paths II with step by step explanation
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Create a 2D dp list with the size of m+1 x n+1, with all elements init
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Create a 2D dp list with the size of m+1 x n+1, with all elements initialized as 0.\n2. Set dp[0][1] to 1 as it is the starting point for the robot.\n3. Loop through the grid, if the current element is not an obstacle (obstacleGrid[i-1][j-1] == 0), calculate the number of possible paths to reach the current cell by adding the number of paths from the cell above and the cell on the left (dp[i][j] = dp[i-1][j] + dp[i][j-1]).\n4. Return the number of paths to reach the bottom-right corner (dp[m][n]).\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n        m, n = len(obstacleGrid), len(obstacleGrid[0])\n        dp = [[0] * (n + 1) for _ in range(m + 1)]\n        dp[0][1] = 1\n        for i in range(1, m + 1):\n            for j in range(1, n + 1):\n                if obstacleGrid[i - 1][j - 1] == 0:\n                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1]\n        return dp[m][n]\n\n```
['Python', 'Python3']