Easy Memo 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```java []\nclass Solution {\n    HashMap<String,Integer> hash = new HashMap<>();\n    public int maxOperations(int[] nums) {\n        return f(nums,0,nums.length-1,-1);\n    }\n    public int f(int[] nums,int l,int r,int should){\n        if(l >= r){\n            return 0;\n        }\n        String c = l + "" + r + "" + should;\n        if(hash.containsKey(c)){\n            return hash.get(c);\n        }\n        int first = 0;\n        int last = 0;\n        int fl = 0;\n        if(should == -1){\n            first = f(nums,l+2,r,nums[l] + nums[l+1]) + 1;\n            last = f(nums,l,r-2,nums[r] + nums[r-1]) + 1;\n            fl = f(nums,l+1,r-1,nums[l] + nums[r]) + 1;\n        }\n        else{\n            if(nums[l] + nums[l+1] == should){\n                first = f(nums,l+2,r,should) + 1;\n            }\n            if(nums[r] + nums[r-1] == should){\n                last = f(nums,l,r-2,should) + 1;\n            }\n            if(nums[l] + nums[r] == should){\n                fl = f(nums,l+1,r-1,should) + 1;\n            }\n        }\n        int d = Math.max(first,Math.max(fl,last));\n        hash.put(c,d);\n        return d;\n    }\n}\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Java']