Simple and Easy Understandable Approch
Intuition\nBy using Dynamic Approch(DP)\n\n# Approach\nWe are using Dynamic Approch from the (n-2)nd column. i.e the second column from the last and we are upda
# Intuition\nBy using Dynamic Approch(DP)\n\n# Approach\nWe are using Dynamic Approch from the (n-2)nd column. i.e the second column from the last and we are updating the dp values of the remaining position by comparing the present position with top right position, direct right position and bottom right position.\n\n# Complexity\n- Time complexity:\nO(M\u2217N)\n\n- Space complexity:\nO(M\u2217N)\n\n# Code\n```java []\nclass Solution {\n    public int maxMoves(int[][] grid) {\n        int m = grid.length;\n        int n = grid[0].length;\n\n        int[][] dp = new int[m][n];\n        int maxmoves = 0;\n\n        //here we are starting from the first row from the start and second row from the end\n        for(int col=n-2;col>=0;col--){\n            for(int row=0;row<m;row++){\n                //chechking for top right\n                if(row>0 && grid[row][col] < grid[row-1][col+1]){\n                    dp[row][col] = Math.max(dp[row][col],dp[row-1][col+1]+1);\n                }\n                //checking for direct right\n                if(grid[row][col]<grid[row][col+1]){\n                    dp[row][col] = Math.max(dp[row][col],dp[row][col+1]+1);\n                }\n                //checking for down right\n                if(row<m-1 && grid[row][col] < grid[row+1][col+1]){\n                    dp[row][col] = Math.max(dp[row][col],dp[row+1][col+1]+1);\n                }\n            }\n        }\n        for(int row=0;row<m;row++){\n            maxmoves = Math.max(maxmoves,dp[row][0]);\n        }\n        return maxmoves;\n    }\n}\n```
['Java']