Just BFS
Intuition\nJust BFS\n\n# Approach\nBFS\n\n# Complexity\n- Time complexity:\nO(n * m)\n\nO(n * m)\n\n# Code\n\nclass Solution {\npublic:\n    int maxMoves(vector
# Intuition\nJust BFS\n\n# Approach\nBFS\n\n# Complexity\n- Time complexity:\nO(n * m)\n\nO(n * m)\n\n# Code\n```\nclass Solution {\npublic:\n    int maxMoves(vector<vector<int>>& grid) {\n        const int m = grid.size(), n = grid[0].size();\n        vector<vector<bool>> mark(2, vector<bool>(m));\n        mark[0] = vector<bool>(m, true);\n        for (int i = 1, last = 0; i < n; ++i) {\n            const int now = last ^ 1;\n            mark[now] = vector<bool>(m);\n            bool can = false;\n            for (int j = 0; j < m; ++j) {\n                mark[now][j] = (mark[last][j] && grid[j][i] > grid[j][i - 1]) \n                    || (j && mark[last][j - 1] && grid[j][i] > grid[j - 1][i - 1])\n                    || (j + 1 < m && mark[last][j + 1] && grid[j][i] > grid[j + 1][i - 1]);\n                can = can || mark[now][j];\n            }\n            if (!can) {\n                return i - 1;\n            }\n            last = now;\n        }\n        return n - 1;\n        \n    }\n};\n```
['C++']