✅✅ || C++ || Clean and Easy Explanation || DP || Memoization || ✅✅
Intuition\n Describe your first thoughts on how to solve this problem. \n- This problem is same as to take that path or not.(take, not take kinda)\n- We are sto
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- This problem is same as to take that path or not.(take, not take kinda)\n- We are storing tatal paths of the grid indexes.(by checking one by on in left direction and down).\n- If there\'s a obstacle we\'ll store 0 paths for that.\n- If we are at destination, simply return.\n- Otherwise take action in either direction and add both total ways.\n- Store it in dp table for space optimization.\n\n# Complexity\n- Time complexity: O(2^n) : exponential due to recursive calls\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n\xB2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int helper(vector<vector<int>>& grid, int i, int j, int t[101][101]){\n        if(i==grid.size() || j==grid[0].size()) return 0; // base case\n        if(grid[i][j]==1)return 0; // obstacle\n        if(i==grid.size()-1 && j==grid[0].size()-1)return 1; // destiny\n        if(t[i][j]!=-1)return t[i][j]; // already calculated\n        return t[i][j] = helper(grid, i+1, j, t) + helper(grid, i, j+1, t);\n    }\n\n    int uniquePathsWithObstacles(vector<vector<int>>& grid) {\n        int t[101][101];\n        memset(t, -1, sizeof t);\n        return helper(grid, 0, 0, t);\n\n    }\n};\n```
['Array', 'Dynamic Programming', 'Memoization', 'Matrix', 'C++']