🔥DP || ⚡Memoization || ✅Clean Code
Connect with me on LinkedIN : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n\n# Complexity\n\n- Time complexity:\nO(n * n)\n\n- Space complexity:\
## Connect with me on LinkedIN : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n\n# Complexity\n```\n- Time complexity:\nO(n * n)\n\n- Space complexity:\nO(n * n)\n```\n\n# Code\n## Please Upvote if it helps\uD83E\uDD17\n```\nclass Solution {\npublic:\n    int dp[2001][2001];\n    int helper(int i, int j, vector<int>& nums, int score){\n        if(i >= j)\n            return 0;\n        if(dp[i][j] != -1)\n            return dp[i][j];\n        int maxi = 0;\n        if(nums[i] + nums[j] == score)\n            maxi = max(maxi, 1 + helper(i + 1, j - 1, nums, score));\n        if(nums[i] + nums[i + 1] == score)\n            maxi = max(maxi, 1 + helper(i + 2, j, nums, score));\n        if(nums[j] + nums[j - 1] == score)\n            maxi = max(maxi, 1 + helper(i, j - 2, nums, score));\n        return dp[i][j] = maxi;\n            \n    }\n    int maxOperations(vector<int>& nums) {\n        int n = nums.size(), ans = 0;\n        memset(dp, -1, sizeof(dp));\n        ans = max({helper(2, n - 1, nums, nums[0] + nums[1]), helper(0, n - 3, nums, nums[n - 1] + nums[n - 2]), helper(1, n - 2, nums, nums[0] + nums[n - 1])});\n        return ans + 1;\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']