Simple Approach - Backtrack with Memoization | Similar to Longest Increasing Path in a Matrix
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\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```python3 []\nclass Solution:\n    def maxMoves(self, grid: List[List[int]]) -> int:\n\n        rows,cols = len(grid),len(grid[0])\n        cache = {}\n\n        def backtrack(r,c,prev):\n\n            if(\n                r<0 or\n                c<0 or\n                r==rows or\n                c==cols or\n                prev>=grid[r][c]\n            ):\n                return 0\n            \n            if (r,c) in cache:\n                return cache[(r,c)]\n\n            prev = grid[r][c]\n\n            length = 1+ max(backtrack(r-1,c+1,prev),\n                            backtrack(r,c+1,prev),\n                            backtrack(r+1,c+1,prev))\n\n            cache[(r,c)] = length\n\n            return length\n\n        max_moves = 0\n\n        for r in range(rows):\n            length = backtrack(r,0,float(\'-inf\'))-1\n            max_moves = max(max_moves,length)    \n    \n        return max_moves\n\n\n        \n```
['Python3']