Easy C++ Solution || (Using DP) ✅✅
Code\n\nclass Solution {\npublic:\n    int helper(vector<int> &nums,int i,int j,int prev,int n,vector<vector<int>> &dp){\n        if(i>=j){\n            return 
# Code\n```\nclass Solution {\npublic:\n    int helper(vector<int> &nums,int i,int j,int prev,int n,vector<vector<int>> &dp){\n        if(i>=j){\n            return 0;\n        }\n        int ans=0;\n        if(dp[i][j]!=-1){\n            return dp[i][j];\n        }\n        if((nums[i]+nums[j])==prev || prev==-1){\n            ans=max(ans,1+helper(nums,i+1,j-1,nums[i]+nums[j],n,dp));\n        }\n        if(i+2<=j){\n            if((nums[i]+nums[i+1])==prev || prev==-1){\n                 ans=max(ans,1+helper(nums,i+2,j,nums[i]+nums[i+1],n,dp));\n            }\n        }\n        if(j-2>=i){\n            if((nums[j]+nums[j-1])==prev || prev==-1){\n                 ans=max(ans,1+helper(nums,i,j-2,nums[j]+nums[j-1],n,dp));\n            }\n        }\n        return dp[i][j]=ans;\n    }\n    int maxOperations(vector<int>& nums) {\n        int n=nums.size();\n        vector<vector<int>> dp(n,vector<int>(n,-1));\n        return helper(nums,0,n-1,-1,n,dp);\n    }\n};\n```\n# **PLEASE UPVOTE IF IT HELPED** \u2B06\uFE0F\n\n#\n\n
['Dynamic Programming', 'C++']