✅Multiple Approaches -- BFS,DP(memo) explained |  Explore all possibility and take max
IMPORTANT\nYou can watch the biggest sliding window series on entire internet and backtracking just using single template by clicking my profile icon and checki
**IMPORTANT**\nYou can watch the biggest sliding window series on entire internet and backtracking just using single template by clicking my profile icon and checking my youtube channel link from the bio. ( I bet you can solve any sliding window question on leetcode after watching the series do share you thoughts on the same.)\nThankyou and happy leetcoding.\n\nFor below solution if there is doubt let me know.\n\n**NOTE:** It is very general question that is asked very often just remember one thing that if you have many options to go just think dp (recursion will give TLE , you have to memoise it) that you can explore all the paths and whatever is asked just return with that like here maximum so return max(op1,op2,...) and with BFS also you can do same just push all the possible (row,col) index to queue so that you will process it of this and always update maximum value.\n\n**Approach 1: BFS**\n\n```\nclass Solution {\npublic:\n    int maxMoves(vector<vector<int>>& grid) {\n         int m = grid.size();\n    int n = grid[0].size();\n    int mx = 0;\n\n    vector<vector<int>> dp(m,vector<int>(n, 0));  // for storing moves at each (row,col) if calculated so that no need to calculate again\n    queue<pair<int, int>> q;\n\n    // Start BFS from cells in the first column\n    for (int i = 0; i < m; i++) {\n        q.push(make_pair(i, 0));         \n        dp[i][0] = 1;\n    }\n\n    // Perform BFS\n    while (!q.empty()) {\n        int row = q.front().first;\n        int col = q.front().second;\n        q.pop();\n\n        int moves = dp[row][col];  // if we have already calculated number of moves at this (row,col)\n        mx = max(mx, moves);\n\n        // Check the three possible moves whichever moves is generated maximum is our answer\n        for (int i = -1; i <= 1; i++) {\n            int newRow = row + i;       // will generate row-1,row,row+1 (all three possibility)\n            int newCol = col + 1;       // given in question  for all case its col+1\n\n            if (newRow >= 0 && newRow < m && newCol < n && grid[newRow][newCol] > grid[row][col] && dp[newRow][newCol] < moves + 1) {\n                dp[newRow][newCol] = moves + 1;   // increase the count of moves\n                q.push({newRow,newCol});          // push this new points in queue may it generate maximum moves \n            }\n        }\n    }\n\n    return mx-1;\n}\n\n};\n```\n\n**Approach 2: DP (memo)**\n\n* Ask yourself a question that how many options are there to move from first column of each cell\n* 3 Right, so just explore all these path by taking maximum as moves by adding 1 to each options\n* Just make sure that before calling these option check its bound that is it feasible to call.\n* All done you have got the answer.\n\n```\n  int dfs(int i, int j, int n, int m, vector<vector<int>> &grid, vector<vector<int>> &dp) {\n       \n        if(dp[i][j] != -1) return dp[i][j];\n        \n        int op1 = 0, op2 = 0, op3 = 0;\n        if(i>=1 and j<m-1 and grid[i][j] < grid[i - 1][j + 1]) op1 = 1 + dfs(i - 1, j + 1, n, m, grid, dp);\n        if(j<m-1 and grid[i][j] < grid[i][j + 1]) op2 = 1 + dfs(i, j + 1, n, m, grid, dp);\n        if(i<n-1 and j<m-1 and grid[i][j] < grid[i + 1][j + 1]) op3 = 1 + dfs(i + 1, j + 1, n, m, grid, dp);\n    \n        return dp[i][j] = max({op1, op2, op3});\n    }\n\n    int maxMoves(vector<vector<int>>& grid) {\n        int n = grid.size(), m = grid[0].size(), ans = 0;\n        vector<vector<int>> dp(n, vector<int>(m, -1));\n        \n        for(int j=0; j<n; j++) {  // because given that we can start to any cell in first column\n            ans = max(ans, dfs(j, 0, n, m, grid, dp)); // so take max of all those cell from 1st column\n        }\n        return ans;\n        \n    }\n```
['Breadth-First Search', 'C']