Java | 2D array
\n\n# Code\njava []\nclass Solution {\n    public int maxMoves(int[][] grid) {\n        int n = grid.length, m = grid[0].length;\n\n        int[][] dp = new int
\n\n# Code\n```java []\nclass Solution {\n    public int maxMoves(int[][] grid) {\n        int n = grid.length, m = grid[0].length;\n\n        int[][] dp = new int[n][m];\n        for (int col = m - 2; col >= 0; col--) {\n            for (int row = 0; row < n; row++) {\n                int g = grid[row][col];\n                if (row - 1 >= 0 && grid[row - 1][col + 1] > g) {\n                    dp[row][col] = Math.max(dp[row][col],\n                            1 + dp[row - 1][col + 1]);\n                }\n                if (grid[row][col + 1] > g) {\n                    dp[row][col] = Math.max(dp[row][col], 1 + dp[row][col + 1]);\n                }\n                if (row + 1 < n && grid[row + 1][col + 1] > g) {\n                    dp[row][col] = Math.max(dp[row][col],\n                            1 + dp[row + 1][col + 1]);\n                }\n            }\n        }\n\n        int count = 0;\n        for (int[] d : dp) {\n            count = Math.max(count, d[0]);\n        }\n        return count;\n    }\n}\n```
['Java']