Very Easy DP Solution
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 {\npublic:\n    int fun(int sum,int i,int j,vector<int> &a,vector<vector<int>> &dp){\n        if(i>=j)  return 0;\n        // cout<<i<<" "<<j<<endl;\n\n        if(dp[i][j]!=-1)    return dp[i][j];\n\n        int a1=0,a2=0,a3=0;\n        if(a[i]+a[i+1]==sum)  a1=fun(sum,i+2,j,a,dp)+1;\n        if(a[i]+a[j]==sum)  a2=fun(sum,i+1,j-1,a,dp)+1;\n        if(a[j]+a[j-1]==sum)  a3=fun(sum,i,j-2,a,dp)+1;\n\n        // cout<<a1<<" "<<a2<<" "<<a3<<endl;\n        dp[i][j]=max(a1,max(a2,a3));\n        return dp[i][j];\n    }\n\n    int maxOperations(vector<int>&  a) {\n        int n=a.size();\n        vector<vector<int>> dp(n,vector<int>(n,-1));\n\n        int ans1=fun(a[0]+a[1],2,n-1,a,dp)+1;\n        int ans2=fun(a[0]+a[n-1],1,n-2,a,dp)+1;\n        int ans3=fun(a[n-1]+a[n-2],0,n-3,a,dp)+1;\n\n        int ans=max(ans1,max(ans2,ans3));\n        return ans;\n    }\n};\n```
['C++']