✅ Are you tired of getting TLE using recursive solution ?? | ✅[C++] + DP solution | DLC, May20
\nclass Solution {\npublic:\n    int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n        int m = obstacleGrid.size();\n        int n = obstac
```\nclass Solution {\npublic:\n    int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n        int m = obstacleGrid.size();\n        int n = obstacleGrid[0].size();\n        \n        vector<vector<int>> dp(m, vector<int>(n, -1));      //stores no of paths at each point\n        \n        //return no. of unique paths\n        return helper(obstacleGrid, dp, 0, 0);\n    }\n    \n    int helper(vector<vector<int>>& obstacleGrid, vector<vector<int>>& dp, int i, int j){\n        int m = obstacleGrid.size(), n = obstacleGrid[0].size();\n        if(i<0 || j<0 || i>=m || j>=n || obstacleGrid[i][j]==1) //out of boundary\n             return 0;\n        \n        if(dp[i][j] != -1)      //if already have the valuem, use that to calc no of paths\n            return dp[i][j];\n        \n        if(i==m-1 && j==n-1)    //if reached to correct pos, got 1 path\n             return 1;\n        \n        //Now we need to calc the no of unique paths, in right and bottom direction\n        return dp[i][j] = helper(obstacleGrid, dp, i, j+1) + helper(obstacleGrid, dp, i+1, j);\n    }\n};\n```
[]