🔥C++ ✅✅ Best Solution 🔥 🔥 Easy to Understand💯💯 ⬆⬆⬆
\n\n# Complexity\n- Time complexity: O(n * m)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n * m)\n Add your space complexity here, e.g.
\n\n# Complexity\n- Time complexity: $$O(n * m)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n * m)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define vi vector<int>\n#define vvi vector<vi>\n\nclass Solution {\npublic:\n    int maxMoves(vector<vector<int>>& grid) {\n        int n = grid.size(), m = grid[0].size();\n        vvi temp(n, vi(m, 0));\n        for(int i=0; i<n; i++) temp[i][0] = 1;\n        \n        for(int i=1; i<m; i++)  {\n            for(int j=0; j<n; j++)  {\n                if(grid[j][i] > grid[j][i-1] && temp[j][i-1])   temp[j][i] = 1;\n                if(j-1 >=0 && grid[j][i] > grid[j-1][i-1] && temp[j-1][i-1])   temp[j][i] = 1;\n                if(j+1<n && grid[j][i] > grid[j+1][i-1] && temp[j+1][i-1])   temp[j][i] = 1;\n            }\n        }\n        \n        for(int i=1; i<m; i++)  {\n            int cnt = 0;\n            for(int j=0; j<n; j++)  {\n                if(temp[j][i] == 1) cnt++;\n            }\n            if(cnt == 0)    return i-1;\n        }\n        return m-1;\n    }\n};\n```
['Array', 'Breadth-First Search', 'Matrix', 'C++']