Clean Memoization Solution Beats 90 %
\n# Code\n\nclass Solution {\n    public int maxOperations(int[] nums) {\n        int n = nums.length;\n        Integer[][] memo = new Integer[n + 1][n + 1];\n\
\n# Code\n```\nclass Solution {\n    public int maxOperations(int[] nums) {\n        int n = nums.length;\n        Integer[][] memo = new Integer[n + 1][n + 1];\n\n        return helper(nums, 0, n - 1, 0, memo);\n    }\n\n    int helper(int[] nums, int start, int end, int prev, Integer[][] memo){\n        if(start >= end) return 0;\n        if(memo[start][end] != null) return memo[start][end];\n\n        int first = 0, last = 0, both = 0;\n\n        if(nums[start] + nums[start +1] == prev || (start == 0 && end == nums.length -1)){\n            first = 1 + helper(nums, start +2, end, nums[start] + nums[start +1], memo);\n        }\n        if(nums[end] + nums[end -1] == prev || (start == 0 && end == nums.length -1)){\n            last = 1 +  helper(nums, start, end -2, nums[end] + nums[end -1], memo);\n        } \n        if(nums[start] + nums[end] == prev || (start == 0 && end == nums.length -1)){\n            both = 1 +  helper(nums, start +1, end -1, nums[start] + nums[end], memo);\n        }\n\n        return memo[start][end] = Math.max(first, Math.max(both, last));\n    }\n}\n```
['Dynamic Programming', 'Memoization', 'Java']