Java/C DP simple solution(O(M*N))
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Suppose we have the 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Suppose we have the following grid:\ngrid:\n**[[2, 4, 3],\n [3, 2, 6],\n [4, 5, 1]]**\n2. Step 1: Initialize DP Table\nThe DP table dp[i][j] is used to store the maximum moves possible to reach cell (i, j). Initially, set all elements of the first column dp[i][0] to 1, as any element from the first column can be the starting point:\ndp :\n**[1, 0, 0]\n  [1, 0, 0]\n  [1, 0, 0]**\n2. Step 2: Fill the DP Table\nWe update dp[i][j] by checking three possible moves from cells in the previous column (j-1).\n\n4. Let\'s go column by column to see the changes in dp.\n5. **Column 1 (j = 1)**\n\n    - **Cell (0,1): grid[0][1] = 4**\n        - Check (i-1, j-1): Not valid, as it is out of bounds.\n        - Check (i, j-1): grid[0][0] = 2, and 4 > 2, so we can move from (0, 0) to (0, 1). Update dp[0][1] = dp[0][0] + 1 = 2.\n        - Check (i+1, j-1): grid[1][0] = 3, and 4 > 3, so we can move from (1, 0) to (0, 1). Update dp[0][1] = max(dp[0][1], dp[1][0] + 1) = 2.\n        - dp[0][1] = 2\n\n    - **Cell (1,1): grid[1][1] = 2**\n        - Check (i-1, j-1): grid[0][0] = 2, but 2 is not greater than 2, so no move.\n        - Check (i, j-1): grid[1][0] = 3, but 2 is not greater than 3, so no move.\n        - Check (i+1, j-1): grid[2][0] = 4, but 2 is not greater than 4, so no move.\n        - dp[1][1] = 0\n\n    - **Cell (2,1): grid[2][1] = 5**\n        - Check (i-1, j-1): grid[1][0] = 3, and 5 > 3, so we can move from (1, 0) to (2, 1). Update dp[2][1] = dp[1][0] + 1 = 2.\n        - Check (i, j-1): grid[2][0] = 4, and 5 > 4, so we can move from (2, 0) to (2, 1). Update dp[2][1] = max(dp[2][1], dp[2][0] + 1) = 2.\n        - dp[2][1] = 2\n\nAfter processing column 1:\n**dp :\n  [1, 2, 0]\n  [1, 0, 0]\n  [1, 2, 0]**\n6. **Column 2 (j = 2)**\n    - **Cell (0,2): grid[0][2] = 3**\n        - Check (i-1, j-1): Not valid, as it is out of bounds.\n        - Check (i, j-1): grid[0][1] = 4, but 3 is not greater than 4, so no move.\n        - Check (i+1, j-1): grid[1][1] = 2, and 3 > 2, so we can move from (1, 1) to (0, 2). Update dp[0][2] = dp[1][1] + 1 = 1.\n        - dp[0][2] = 1\n\n    - **Cell (1,2): grid[1][2] = 6**\n        - Check (i-1, j-1): grid[0][1] = 4, and 6 > 4, so we can move from (0, 1) to (1, 2). Update dp[1][2] = dp[0][1] + 1 = 3.\n        - Check (i, j-1): grid[1][1] = 2, and 6 > 2, so we can move from (1, 1) to (1, 2). Update dp[1][2] = max(dp[1][2], dp[1][1] + 1) = 3.\n        - Check (i+1, j-1): grid[2][1] = 5, and 6 > 5, so we can move from (2, 1) to (1, 2). Update dp[1][2] = max(dp[1][2], dp[2][1] + 1) = 3.\n        - dp[1][2] = 3\n\n    - **Cell (2,2): grid[2][2] = 1**\n        - Check (i-1, j-1): grid[1][1] = 2, but 1 is not greater than 2, so no move.\n        - Check (i, j-1): grid[2][1] = 5, but 1 is not greater than 5, so no move.\n        - Check (i+1, j-1): Not valid, as it is out of bounds.\n        - dp[2][2] = 0\n\nAfter processing column 2:\n**dp = \n  [1, 2, 1]\n  [1, 0, 3]\n  [1, 2, 0]**\n7. **Result:\nThe maximum value in dp[i][j] - 1 is 2 (from dp[1][2] - 1), so maxMoves returns 2. This indicates that the longest path of strictly increasing values achievable by moving only rightward neighbors is of length 2 moves.**\n# Complexity\n- Time complexity:O(M*N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(M*N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int maxMoves(int[][] grid) {\n        int m = grid.length, n = grid[0].length;\n        int[][] dp = new int[m][n];\n        for (int i = 0; i < m; i++) {\n            //since any element from column 0 is selectable \n            dp[i][0] = 1;\n        }\n        int maxMoves = 0;\n        for (int j = 1; j < n; j++) {\n            for (int i = 0; i < m; i++) {\n                //(row-1,col+1)\n                if (i - 1 >= 0 && grid[i][j] > grid[i - 1][j - 1] && dp[i - 1][j - 1] > 0) {\n                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - 1] + 1);\n                }\n                //(row,col+1)\n                if (grid[i][j] > grid[i][j - 1] && dp[i][j - 1] > 0) {\n                    dp[i][j] = Math.max(dp[i][j], dp[i][j - 1] + 1);\n                }\n                //(row+1,col+1)\n                if (i + 1 < m && grid[i][j] > grid[i + 1][j - 1] && dp[i + 1][j - 1] > 0) {\n                    dp[i][j] = Math.max(dp[i][j], dp[i + 1][j - 1] + 1);\n                }\n                maxMoves = Math.max(maxMoves, dp[i][j] - 1);\n            }\n        }\n        return maxMoves;\n    }\n}\n```\n```C []\nint maxMoves(int** grid, int gridSize, int* gridColSize) {\n    int m = gridSize, n = gridColSize[0];\n    int** dp = (int**)malloc(m * sizeof(int*));\n    for (int i = 0; i < m; i++) {\n        dp[i] = (int*)calloc(n, sizeof(int));\n        dp[i][0] = 1;\n    }\n    int maxMoves = 0;\n    for (int j = 1; j < n; j++) {\n        for (int i = 0; i < m; i++) {\n            // Check (row-1, col+1)\n            if (i - 1 >= 0 && grid[i][j] > grid[i - 1][j - 1] && dp[i - 1][j - 1] > 0) {\n                dp[i][j] = dp[i][j] > dp[i - 1][j - 1] + 1 ? dp[i][j] : dp[i - 1][j - 1] + 1;\n            }\n            // Check (row, col+1)\n            if (grid[i][j] > grid[i][j - 1] && dp[i][j - 1] > 0) {\n                dp[i][j] = dp[i][j] > dp[i][j - 1] + 1 ? dp[i][j] : dp[i][j - 1] + 1;\n            }\n            // Check (row+1, col+1)\n            if (i + 1 < m && grid[i][j] > grid[i + 1][j - 1] && dp[i + 1][j - 1] > 0) {\n                dp[i][j] = dp[i][j] > dp[i + 1][j - 1] + 1 ? dp[i][j] : dp[i + 1][j - 1] + 1;\n            }\n            maxMoves = maxMoves > (dp[i][j] - 1) ? maxMoves : (dp[i][j] - 1);\n        }\n    }\n    return maxMoves;\n}\n\n```
['Java']