C++ || Recursion + Memoization || Beginner's Method 🤩💯✅
\n# Code\n\nclass Solution {\npublic:\n    int solve(int i, int j, int score1, vector<int>&nums, vector<vector<int>>&dp){\n        if(i >= j || i > nums.size()-
\n# Code\n```\nclass Solution {\npublic:\n    int solve(int i, int j, int score1, vector<int>&nums, vector<vector<int>>&dp){\n        if(i >= j || i > nums.size()-1 || j < 0) return 0;\n        if(dp[i][j] != 1) return dp[i][j];\n        int pick1 = 0;\n        int pick2 = 0;\n        int pick3 = 0;\n        if(nums[i] + nums[j] == score1 ) pick1 = 1 + solve(i+1, j-1, score1,  nums, dp);\n        if(nums[i] + nums[i+1] == score1 ) pick2 = 1 +solve(i+2, j, score1,  nums, dp);\n        if(nums[j] + nums[j-1] == score1 ) pick3 = 1 + solve(i, j-2, score1,  nums, dp);\n        return dp[i][j] =  max(pick1, max(pick2, pick3));\n        \n    }\n    \n    int maxOperations(vector<int>& nums) {\n        int i = 0;\n        int j = nums.size()-1;\n        int n = nums.size();\n        int score1 = nums[i] + nums[j];\n        int score2 = nums[i] + nums[i+1];\n        int score3 = nums[j] + nums[j-1];\n        vector<vector<int>>dp1(n, vector<int>(n, 1));\n        vector<vector<int>>dp2(n, vector<int>(n, 1));\n        vector<vector<int>>dp3(n, vector<int>(n, 1));\n        int a = solve(i, j, score1, nums, dp1);\n        int b = solve(i, j, score2,  nums, dp2);\n        int c = solve(i, j, score3,  nums, dp3);\n        int ans = max(a, max(b, c));\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']