Java Solution Using DP || Easy Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nDynamic Programming\n# Approach\n Describe your approach to solving the problem. \nStor
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDynamic Programming\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStore the state in 2d dp Array\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nxm)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(nxm)\n# Code\n```\nclass Solution {\n    public int maxMoves(int[][] g) {\n        int[][] dp = new int[g.length][g[0].length];\n        for(int i=0; i<g.length; i++)\n            for(int j=0; j<g[0].length; j++)\n                dp[i][j] = -1;\n        for(int i=0; i<g.length; i++){\n            dp[i][0] = find(g, i, 0, dp);\n        }\n        int ans = 0;\n        for(int i=0; i<g.length; i++){\n            ans = Math.max(ans, dp[i][0]);\n        }\n        return ans;\n    }\n    public int find(int[][] g, int i, int j, int[][] dp){\n        if(j==g[0].length-1)    return 0;\n        if(dp[i][j] > 0)   return dp[i][j];\n        dp[i][j] = 0;\n        if(i>0 && j<g[0].length-1 && g[i][j]<g[i-1][j+1]){\n            dp[i][j] = Math.max(dp[i][j], 1+find(g, i-1, j+1, dp));\n        }\n        if(j<g[0].length-1 && g[i][j]<g[i][j+1]){\n            dp[i][j] = Math.max(dp[i][j], 1+find(g, i, j+1, dp));\n        }\n        if(i<g.length-1 && j<g[0].length-1 && g[i][j]<g[i+1][j+1]){\n            dp[i][j] = Math.max(dp[i][j], 1+find(g, i+1, j+1, dp));\n        }\n        return dp[i][j] ;\n    }\n}\n```
['Java']