Clean Code | Recursion + Memo | C++
\n# Code\n\nclass Solution {\npublic:\n    int solve(int i,int j,int sum,vector<int>&nums,vector<vector<int>> &dp){\n        if(i>=j) return 0;\n        if(dp[i
\n# Code\n```\nclass Solution {\npublic:\n    int solve(int i,int j,int sum,vector<int>&nums,vector<vector<int>> &dp){\n        if(i>=j) return 0;\n        if(dp[i][j]!=-1) return dp[i][j]; \n        int ans1=0,ans2=0,ans3=0;\n        if(nums[i]+nums[i+1]==sum) ans1 = 1 + solve(i+2,j,sum,nums,dp);\n        if(nums[j]+nums[j-1]==sum) ans2 = 1 + solve(i,j-2,sum,nums,dp);\n        if(nums[i]+nums[j]==sum) ans3 = 1 + solve(i+1,j-1,sum,nums,dp);\n        return dp[i][j] = max(ans1,max(ans2,ans3));\n    }\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 ans1 = solve(2,n-1,nums[0]+nums[1],nums,dp1) + 1;\n        int ans2 = solve(0,n-3,nums[n-1]+nums[n-2],nums,dp2) + 1;\n        int ans3 = solve(1,n-2,nums[0]+nums[n-1],nums,dp3) + 1;\n        return max(ans1,max(ans2,ans3));\n    }\n};\n```
['C++']