Easy Recursive 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 {\n    int solve(int i, int j, int val, vector<int>& nums, vector<vector<int> >& dp){\n        if(i >= j) return 0;\n\n        if(dp[i][j] != -1) return dp[i][j];\n\n        int ans = 0;\n        if(nums[i] + nums[j] == val){\n            ans = max(ans, 1+solve(i+1, j-1, val, nums, dp));\n        }\n        if(nums[i] + nums[i+1] == val){\n            ans = max(ans, 1+solve(i+2, j, val, nums, dp));\n        }\n        if(nums[j-1] + nums[j] == val){\n            ans = max(ans, 1+solve(i, j-2, val, nums, dp));\n        }\n\n        return dp[i][j] = ans;\n    }\npublic:\n    int maxOperations(vector<int>& nums) {\n        int n = nums.size();\n        int ans = 0;\n        vector<vector<int> > dp(n, vector<int> (n, -1));\n        ans = max(ans, 1+solve(2, n-1, nums[0]+nums[1], nums, dp));\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < n; j++) dp[i][j] = -1;\n        }\n        ans = max(ans, 1+solve(0, n-3, nums[n-1]+nums[n-2], nums, dp));\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < n; j++) dp[i][j] = -1;\n        }\n        ans = max(ans, 1+solve(1, n-2, nums[0]+nums[n-1], nums, dp));\n\n        return ans;\n    }\n};\n```
['Array', 'Dynamic Programming', 'Memoization', 'C++']