✅ C++ || Easy to Understand || Recursion ➡️ Memoization ➡️ Tabulation
1. Recursion\n\n\nint solveRec(int m,int n,vector<vector<int>>& obstacleGrid){\n        if(m>=obstacleGrid.size() || n>=obstacleGrid[0].size() || obstacleGrid[m
**1. Recursion**\n\n```\nint solveRec(int m,int n,vector<vector<int>>& obstacleGrid){\n        if(m>=obstacleGrid.size() || n>=obstacleGrid[0].size() || obstacleGrid[m][n]==1) return 0;    \n        if(m==obstacleGrid.size()-1 && n==obstacleGrid[0].size()-1) return 1;                                           \n        int down=solveRec(m+1,n,obstacleGrid);\n        int right=solveRec(m,n+1,obstacleGrid);\n        int ans=down+right;\n        return ans;\n    }\n int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n        return solveRec(0,0,obstacleGrid);\n  }\n```\n\n**2. Memoization**\n\n```\nint solveMem(int m,int n,vector<vector<int>>& obstacleGrid,vector<vector<int>>&dp){\n        if(m>=obstacleGrid.size() || n>=obstacleGrid[0].size() || obstacleGrid[m][n]==1) return 0;\n        if(m==obstacleGrid.size()-1 && n==obstacleGrid[0].size()-1) return 1;\n        if(dp[m][n]!=-1) return dp[m][n];\n        int down=solveMem(m+1,n,obstacleGrid,dp);\n        int right=solveMem(m,n+1,obstacleGrid,dp);\n        int ans=down+right;\n        return dp[m][n]=ans;  \n    }\n  int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n         vector<vector<int>>dp(obstacleGrid.size(),vector<int>(obstacleGrid[0].size(),-1));\n         return solveMem(0,0,obstacleGrid,dp);\n  }\n```\n**3. Tabulation**\n\n```\nint solveTab(vector<vector<int>>& obstacleGrid){\n        int m=obstacleGrid.size();\n        int n=obstacleGrid[0].size();\n        if(obstacleGrid[0][0]==1) return 0;\n        vector<vector<int>>dp(m,vector<int>(n,0));\n        dp[0][0]=1;\n        for(int i=0;i<m;i++){\n            for(int j=0;j<n;j++){\n                if(i==0 && j==0) continue;\n                \n                if(obstacleGrid[i][j]==0){ // if there is no obstacle present in the grid\n                    \n                    int moveUp=0;\n                    int moveleft=0;\n                    \n                    if(i-1>=0){\n                        moveUp=dp[i-1][j];\n                    }\n                    if(j-1>=0){\n                        moveleft=dp[i][j-1];\n                    }\n                    dp[i][j]=moveUp+moveleft;\n                }\n            }\n        }\n        return dp[m-1][n-1];\n    }\n int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n        return solveTab(obstacleGrid);\n  }\n```\n**Don\'t forget to upvote this post if it has helped you!!!**
[]