Beats 100 % || Most Efficient Solution and Easy to Understand || C++
\n\n# Code\n\nclass Solution {\npublic:\n    int uniquePathsWithObstacles(vector<vector<int>>& grid) {\n        int n = grid.size() , m = grid[0].size();\n     
\n\n# Code\n```\nclass Solution {\npublic:\n    int uniquePathsWithObstacles(vector<vector<int>>& grid) {\n        int n = grid.size() , m = grid[0].size();\n        long long mod = 2e9+7;\n        vector<int>prev(m,0);\n        for(int i=0;i<n;i++){\n            vector<int>curr(m,0);\n            for(int j=0;j<m;j++){\n                \n                if(i>=0 && j>=0 && grid[i][j] == 1){\n                   curr[j] = 0;\n                    // continue;\n                } \n                else if(i==0 && j==0){\n                    curr[j] = 1;\n                    // continue;\n                } \n                else{\n                int up=0,left =0;\n               if(i>0){\n                   up = prev[j];\n               }\n               if(j>0){\n                   left =curr[j-1];\n               } \n                curr[j] = ( up + left) % mod ;\n                }\n            }\n            prev = curr;\n        }\n        \n        return prev[m-1];\n    }\n};\n```
['C++']