C++ || Easy solution using Recursion and Memoization || Faster than 100%
Intuition\n### Since we have 3 choices and have to choose the maximum therefore DP should be the first thought\n Describe your first thoughts on how to solve th
# Intuition\n### Since we have 3 choices and have to choose the maximum therefore DP should be the first thought\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Declare a 2D DP with size N*N.\n2. Call the solve function for all the 3 choices.\n3. In the function i>=j return 0 as we cannot choose 2 elements.\n4. Now check if we have already calculated or not, if yes then return it.\n5. Now check for all 3 choices if they are equal to sum call the solve function and update the ans.\n6. Store the ans in the dp to memoize.\n7. Return the ans as the maximum from all the choices.\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 {\nprivate:\n    int solve(int i,int j,int sum,vector<int>& arr,vector<vector<int>>& dp)\n    {\n        //Base case\n        if(i>=j)\n            return 0;\n        \n        //Check if already calculated\n        if(dp[i][j]!=-1)\n            return dp[i][j];\n        \n        int ans=0;\n        \n        //First choice\n        if(arr[i]+arr[i+1]==sum)\n            ans=max(ans,solve(i+2,j,sum,arr,dp)+1);\n        \n        //Second choice\n        if(arr[j]+arr[j-1]==sum)\n            ans=max(ans,solve(i,j-2,sum,arr,dp)+1);\n        \n        //Third choice\n        if(arr[i]+arr[j]==sum)\n            ans=max(ans,solve(i+1,j-1,sum,arr,dp)+1);\n        \n        //Memoize\n        return dp[i][j]=ans;\n        \n    }\npublic:\n    int maxOperations(vector<int>& nums) \n    {\n        int n=nums.size();\n        \n        //Declare the Dp\n        vector<vector<int>> dp(n+2,vector<int>(n+2,-1));\n        \n        //Call the function for all the 3 choices\n        int a=solve(2,n-1,nums[0]+nums[1],nums,dp);\n        int b=solve(0,n-3,nums[n-1]+nums[n-2],nums,dp);\n        int c=solve(1,n-2,nums[0]+nums[n-1],nums,dp);\n\n        //Return the max of the answers\n        return max(a,max(b,c))+1;\n    }\n};\n```\n# Please Upvote if helps!!!
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']