Easy and Intuitive Top Down Dynamic Programming 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: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n// subproblem \n// (l, r, score) -> max number of operations of this subproblem\n\n// memo only needs l and r, becuase each l + r combo will have a unique score\n\nclass Solution {\n    int max;\n    int[] nums;\n    Integer[][] memo;\n    public int maxOperations(int[] nums) {\n        this.max = 0;\n        this.nums = nums;\n        if(nums.length == 0) return max;\n        if(nums.length == 1) return max;\n\n        this.memo = new Integer[nums.length][nums.length];\n        dfs(0, nums.length - 1, null);\n        return max;\n    }\n\n    private int dfs(int l, int r, Integer score) {\n        if(l >= r) return 0;\n        if(l == nums.length) return 0;\n        if(memo[l][r] != null) return memo[l][r];\n\n        int maxIfFirst2 = 0;\n        int maxIfLast2 = 0;\n        int maxIfFirstAndLast = 0;\n\n        // delete first 2\n        if(score == null || nums[l] + nums[l + 1] == score) {\n            maxIfFirst2 = dfs(l + 2, r, nums[l] + nums[l + 1]) + 1;\n        }\n\n        // delete last 2\n        if(score == null || nums[r] + nums[r - 1] == score) {\n            maxIfLast2 = dfs(l, r - 2, nums[r] + nums[r - 1]) + 1;\n        }\n\n        // delete first and last\n        if(score == null || nums[l] + nums[r] == score) {\n            maxIfFirstAndLast = dfs(l + 1, r - 1, nums[l] + nums[r]) + 1;\n        }\n\n        int currentMax = Math.max(maxIfFirst2, Math.max(maxIfLast2, maxIfFirstAndLast));\n        max = Math.max(max, currentMax);\n\n        memo[l][r] = currentMax;\n\n        return currentMax;\n    }\n}\n```
['Java']