Easy memoization approach✅ beats 85%
Intuition\nAs mentioned in the question we need to find the maximum number of operations we can perform that yield same score.\nwe can perform the following ope
# Intuition\nAs mentioned in the question we need to find the maximum number of operations we can perform that yield same score.\nwe can perform the following operations\n1. delete first two elements\n2. delete last two elements\n3. delete first and last elements\n\n\n# Approach\nso the approach is to recursively shrink the array by deleting the elements in it so we are taking two indexes  **i** , **j** where\n **i** - represents starting of the array and \n**j** - represents the ending of the array\n\n# Complexity\n- Time complexity:\nAs we are using memoization approach time complexity will be **O(n^2)**\n\n- Space complexity:\nwe are using an dp array which which of size **n^2**\nrecursive stack space of size **n**\nTotal space  complexity is **O(n^2)**\n\n# Code\n```\nclass Solution(object):\n    def memoization(self,i,j,score,nums,dp):\n        if j<=i: # when the array is shrinked to 1 or 0 elements we simply return 0\n            return 0\n        if dp[i][j] !=-1:\n            return dp[i][j]\n        first = 0\n        last = 0\n        firstLast = 0 \n        if (nums[i]+nums[i+1])==score:\n            first = 1+self.memoization(i+2,j,score,nums,dp) #deleting the first two elements\n        if (nums[i]+nums[j])==score:\n            firstLast = 1+self.memoization(i+1,j-1,score,nums,dp) #deleting the first and last elements\n        if (nums[j]+nums[j-1])==score:\n            last = 1+self.memoization(i,j-2,score,nums,dp) #deleting the last two elements\n        dp[i][j] = max(first,last,firstLast)\n        return dp[i][j]\n    def maxOperations(self, nums):\n        n = len(nums)\n        dp = [[-1]*n for _  in range(n)]\n        first = self.memoization(2,n-1,nums[0]+nums[1],nums,dp)\n        firstLast = self.memoization(1,n-2,nums[0]+nums[n-1],nums,dp)\n        last = self.memoization(0,n-3,nums[n-1]+nums[n-2],nums,dp)\n        return 1+max(first,last,firstLast)\n\n\n        \n```
['Dynamic Programming', 'Memoization', 'Python']