Easy approach | Recursion + Memoization
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    public int maxOperations(int[] nums) {\n        int n = nums.length;\n        if (n < 2) {\n            return 0;\n        }\n\n        int [][] dp = new int[n][n];\n        for (int [] arr : dp) {\n            Arrays.fill(arr, -1);\n        }\n\n        int firstTwo = 1 + helper(nums, 2, n - 1, nums[0] + nums[1], dp);\n        int lastTwo = 1 + helper(nums, 0, n - 3, nums[n - 2] + nums[n - 1], dp);\n        int firstAndLast = 1 + helper(nums, 1, n - 2, nums[0] + nums[n - 1], dp);\n\n        return Math.max(firstTwo, Math.max(lastTwo, firstAndLast));\n    }\n\n    public int helper(int [] nums, int i, int j, int prevScore, int [][] dp) {\n        if ((j - i + 1) < 2) {\n            return 0;\n        }\n\n        if (dp[i][j] != -1) {\n            return dp[i][j];\n        }\n\n        int firstTwo = 0;\n        if (nums[i] + nums[i + 1] == prevScore) {\n            firstTwo = 1 + helper(nums, i + 2, j, nums[i] + nums[i + 1], dp);\n        }\n\n        int lastTwo = 0;\n        if (nums[j - 1] + nums[j] == prevScore) {\n            lastTwo = 1 + helper(nums, i, j - 2, nums[j - 1] + nums[j], dp);\n        }\n\n        int firstAndLast = 0;\n        if (nums[i] + nums[j] == prevScore) {\n            firstAndLast = 1 + helper(nums, i + 1, j - 1, nums[i] + nums[j], dp);\n        }\n\n        return dp[i][j] = Math.max(firstTwo, Math.max(lastTwo, firstAndLast));\n    }\n}\n```
['Recursion', 'Memoization', 'Java']