[Java] Recursion -> Memoization -> DP Solutions
Recursion : TLE\n\nclass Solution {\n    public int uniquePathsWithObstacles(int[][] obstacleGrid) {\n        int m = obstacleGrid.length;\n        int n = obst
**Recursion : TLE**\n```\nclass Solution {\n    public int uniquePathsWithObstacles(int[][] obstacleGrid) {\n        int m = obstacleGrid.length;\n        int n = obstacleGrid[0].length;\n        return helper(obstacleGrid,0,0,m,n);\n    }\n    public int helper(int[][] grid,int r,int c,int m,int n){\n        if(r == m || c == n || grid[r][c] == 1)return 0;\n        if(r == m-1 && c == n-1){\n            if(grid[r][c] == 1)return 0;\n            return 1;\n        }\n        return helper(grid,r+1,c,m,n)+helper(grid,r,c+1,m,n);\n    }\n}\n```\n**Memoization : \n41 / 41 test cases passed.\nStatus: Accepted\nRuntime: 4 ms\nMemory Usage: 38.5 MB**\n```\nclass Solution {\n    public int uniquePathsWithObstacles(int[][] obstacleGrid) {\n        int m = obstacleGrid.length;\n        int n = obstacleGrid[0].length;\n        int dp[][] = new int[m][n];\n        return helper(obstacleGrid,0,0,m,n,dp);\n    }\n    public int helper(int[][] grid,int r,int c,int m,int n,int[][] dp){\n        if(r == m || c == n || grid[r][c] == 1)return 0;\n        if(r == m-1 && c == n-1){\n            if(grid[r][c] == 1)return 0;\n            return 1;\n        }\n        if(dp[r][c] > 0)return dp[r][c];\n        return dp[r][c] = helper(grid,r+1,c,m,n,dp)+helper(grid,r,c+1,m,n,dp);\n    }\n}\n```\n**DP :\n41 / 41 test cases passed.\nStatus: Accepted\nRuntime: 0 ms\nMemory Usage: 38 MB**\n```\nclass Solution {\n    public int uniquePathsWithObstacles(int[][] obstacleGrid) {\n        int m = obstacleGrid.length;\n        int n = obstacleGrid[0].length;\n        int dp[][] = new int[m][n];\n        for(int i = m-1;i>=0;i--){\n            for(int j = n-1;j>=0;j--){\n                if(i == m-1 && j == n-1){\n                    if(obstacleGrid[i][j] == 1)dp[i][j] = 0;\n                    else dp[i][j] = 1;\n                }else if(i == m-1 || j == n-1){\n                    if(obstacleGrid[i][j] == 1)dp[i][j] = 0;\n                    else if(i == m-1)dp[i][j] = dp[i][j+1];\n                    else if(j == n-1)dp[i][j] = dp[i+1][j];\n                }else{\n                    if(obstacleGrid[i][j] == 1)dp[i][j] = 0;\n                    else dp[i][j] = dp[i][j+1] + dp[i+1][j];\n                }\n            }\n        }\n        return dp[0][0];\n    }\n}\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Java']