Easy Python DP solution using @cachedy
O(n^2) run time and space time since the cache is (i, j, scr) which are both bounded by n. \nn = len(nums)\nThe scr is bounded by 3 different answers so it is O
O(n^2) run time and space time since the cache is (i, j, scr) which are both bounded by n. \nn = len(nums)\nThe scr is bounded by 3 different answers so it is O(3n^2) ~ O(n^2)\n```\nclass Solution:\n    def maxOperations(self, nums: List[int]) -> int:\n\n        @cache\n        def dfs(l, r, scr):\n            if l >= r: return 0\n\n            ans = 0\n            left = nums[l] + nums[l+1]\n            right = nums[r] + nums[r-1]\n            mid = nums[l] + nums[r]\n\n            if scr==0 or scr == left:\n                ans = max(ans, 1 + dfs(l+2, r, max(scr, left)))\n            if scr == 0 or scr == right:\n                ans = max(ans, 1 + dfs(l, r-2, max(scr, right)))\n            if scr == 0 or scr == mid:\n                ans = max(ans, 1+ dfs(l+1, r-1, max(scr, mid)))\n            return ans\n\n        return dfs(0, len(nums) -1, 0)\n        \n```
['Dynamic Programming', 'Python3']