Java | recursion + memo (top down dp) easy - to - understand
\nclass Solution {\n    int[][] grid;\n    Integer[][] dp;\n    public int maxMoves(int[][] grid) {\n        this.grid = grid;\n        this.dp = new Integer[gr
```\nclass Solution {\n    int[][] grid;\n    Integer[][] dp;\n    public int maxMoves(int[][] grid) {\n        this.grid = grid;\n        this.dp = new Integer[grid.length + 1][grid[0].length + 1];\n        int max = 0;\n        for(int i = 0; i < grid.length; i++) {\n            max = Math.max(max, helper(i, 0, -1) - 1);\n        }\n        return max;\n    }\n    public int helper(int i, int j, int prev) {\n        if(i == grid.length || i < 0 || j == grid[i].length || grid[i][j] <= prev) return 0;\n        if(dp[i][j] != null) return dp[i][j];\n        int left = 1 + helper(i, j + 1, grid[i][j]);\n        int Ddown = 1 + helper(i + 1, j + 1, grid[i][j]);\n        int Dup = 1 + helper(i - 1, j + 1, grid[i][j]);\n        return dp[i][j] = Math.max(left, Math.max(Ddown, Dup));\n    }\n}\n```
['Dynamic Programming', 'Java']