C++ || BFS
Approach\n\nPush the whole first column in queue.\nThen explore as the problem tells to do.\nDont bother to visit a place again even if it is visited from diffe
# Approach\n\nPush the whole first column in queue.\nThen explore as the problem tells to do.\nDont bother to visit a place again even if it is visited from different point as the number of moves are still the same.\n# Complexity\n- Time complexity:\n$O(mn)$\n\n- Space complexity:\n$O(mn)$\n\n# Code\n```\nclass Solution {\npublic:\n    int maxMoves(vector<vector<int>>& grid) {\n        queue<pair<int,int>> q;\n        int m = grid.size();\n        int n = grid[0].size();\n        for(int c=0;c<m;c++){\n            q.push({c,0});\n        }\n        int dir[] = {-1,0,1};\n        vector<vector<int>> visited(m,vector<int>(n,false));\n        int ans = 0;\n        while(!q.empty()){\n            int sz = q.size();\n            while(sz-- > 0){\n                int r = q.front().first;\n                int c = q.front().second;\n                q.pop();\n                if(visited[r][c]) continue;\n                visited[r][c] = true;\n                for(int i=0;i<3;i++){\n                    int R = r+dir[i];\n                    if(R>=0 && R<m && c+1<n && grid[R][c+1]>grid[r][c]) q.push({R,c+1});\n                }\n            }\n            ans++;\n        }\n        return ans-1;\n    }\n};\n```
['Breadth-First Search', 'Queue', 'C++']