Top down DP in python beat 95%
\n# Code\n\nclass Solution:\n    def maxOperations(self, nums: List[int]) -> int:\n        if len(nums) == 2:\n            return 1\n        \n        cache = d
\n# Code\n```\nclass Solution:\n    def maxOperations(self, nums: List[int]) -> int:\n        if len(nums) == 2:\n            return 1\n        \n        cache = dict()\n\n        def do_hash(arr):\n            return \'\'.join(str(x) for x in arr)\n\n        def dp(arr, target_sum):\n            nonlocal cache\n            if len(arr) <= 2:\n                if len(arr) == 2:\n                    return int(sum(arr) == target_sum)\n                return 0\n            \n            hashed_arr = do_hash(arr)\n            if hashed_arr in cache:\n                return cache[hashed_arr]\n\n            temp_result = 0\n            \n            if arr[0] + arr[1] == target_sum:\n                temp_result = max(temp_result, dp(arr[2:], target_sum) + 1)\n            if arr[0] + arr[-1] == target_sum:\n                temp_result = max(temp_result, dp(arr[1:-1], target_sum) + 1)\n            if arr[-2] + arr[-1] == target_sum:\n                temp_result = max(temp_result, dp(arr[:-2], target_sum) + 1)\n            cache[hashed_arr] = temp_result\n            return cache[hashed_arr]\n        \n        opt1_result = dp(nums[2:], nums[0] + nums[1])\n        opt2_result = dp(nums[1:-1], nums[0] + nums[-1])\n        opt3_result = dp(nums[:-2], nums[-2] + nums[-1])\n        return max(opt1_result, opt2_result, opt3_result) + 1\n        \n            \n            \n        \n```
['Python3']