Checking all the 3 possibilities.
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    private:\n    int func(vector<int>& nums,int i,int j,vector<vector<int>>&dp,int val){\n        if(i>=j) return 0;\n        if(dp[i][j]!=-1) return dp[i][j];\n        int op1 = 0,op2 = 0, op3 = 0;\n        if(i+1<=j){\n            if(nums[i]+nums[i+1]==val){\n                op1 = 1 + func(nums,i+2,j,dp,val);\n            }\n        } \n        if(nums[i]+nums[j]==val) op2 = 1 + func(nums,i+1,j-1,dp,val);\n        if(j-1>=i){\n            if(nums[j]+nums[j-1]==val) op3 = 1 + func(nums,i,j-2,dp,val);\n        }\n        return dp[i][j] = max({op1,op2,op3});\n    }\npublic:\n    int maxOperations(vector<int>& nums) {\n        int n = nums.size();\n        vector<vector<int>>dp1(n+1,vector<int>(n+1,-1));\n        vector<vector<int>>dp2(n+1,vector<int>(n+1,-1));\n            vector<vector<int>>dp3(n+1,vector<int>(n+1,-1));\n        int v1 = nums[0]+nums[1];\n        int v2 = nums[0]+nums[n-1];\n        int v3 = nums[n-1]+nums[n-2];\n        int ans = 0;\n        ans = max(ans,func(nums,0,n-1,dp1,v1));\n         ans = max(ans,func(nums,0,n-1,dp2,v2));\n         ans = max(ans,func(nums,0,n-1,dp3,v3));\n        return ans;\n        \n    }\n};\n```
['Dynamic Programming', 'C++']