Answered the question which I bet you had while thinking of intuition.
Intuition\nYou would have thinked that using only 1 dp array of (n x n) would not work, becaue we have to check for 3 different sums.\n\nNow, if sum in second c
# Intuition\nYou would have thinked that **using only 1 dp array of (n x n) would not work**, becaue we have to check for **3 different sums**.\n\n**Now, if sum in second case is different than the first case, the pair of (i,j) for which the condition satisfies will never be marked during first iteration, because we are only applying recusrion if the scores match.**\n\n**Example:** in code, during the first call, sum that we are looking for is 5. Then recursion woud only be called for (i,j) pairs for which the score is 5. During second call, if the sum is 7, no (i,j) pairs for which sum is 5 will be encountered.\n\nThat is the reason why **using only 1 dp array works.**\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 {\npublic:\n    int maxOperations(vector<int>& nums) {\n        int n=nums.size();\n\n        vector<vector<int>> dp(n,vector<int> (n,-1));\n\n        int first=1+getMaxOps(2,n-1,nums,nums[0]+nums[1],dp);\n        int second=1+getMaxOps(0,n-3,nums,nums[n-1]+nums[n-2],dp);\n        int third=1+getMaxOps(1,n-2,nums,nums[0]+nums[n-1],dp);\n\n        return max(first,max(second,third));\n    }\n\nprivate:\n    int getMaxOps(int i,int j,vector<int>& nums,int scoreToLook,vector<vector<int>> &dp){\n        if(j-i+1<2) return 0;\n\n        if(dp[i][j]!=-1) return dp[i][j];\n\n        int score=0;\n        if(nums[i]+nums[i+1]==scoreToLook) score=1+getMaxOps(i+2,j,nums,scoreToLook,dp);\n        if(nums[j]+nums[j-1]==scoreToLook) score=max(score,1+getMaxOps(i,j-2,nums,scoreToLook,dp));\n        if(nums[i]+nums[j]==scoreToLook) score=max(score,1+getMaxOps(i+1,j-1,nums,scoreToLook,dp));\n\n        return dp[i][j]=score;\n    }\n};\n```
['C++']