Python - O(n^2) - Two Pointer - DP - Video Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nI have explained the solution entirely here https://youtu.be/k_r5JB8PWmI\n\n# Approach\
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI have explained the solution entirely here https://youtu.be/k_r5JB8PWmI\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n^2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def maxOperations(self, nums: List[int]) -> int:\n        n= len(nums)\n        \n        @cache\n        def dfs(l, r, score):\n            if l==r or l>r:\n                return 0\n            \n            res = 0\n            if nums[l] + nums[l+1] == score:\n                res = 1 + dfs(l+2, r, score)\n            if nums[l] + nums[r] == score:\n                res = max(res, 1 + dfs(l+1, r-1, score))\n            if nums[r]+ nums[r-1] == score:\n                res = max(res, 1 + dfs(l, r-2, score))\n                \n            return res\n        \n        return 1 + max( dfs(1, n-2, nums[0] +nums[-1]), dfs(2, n-1, nums[0] +nums[1]), dfs(0, n-3, nums[-1] +nums[-2]))\n```
['Python3']