Easy to Understand and Easy Approach 😊😊
ApproachThe given code is designed to find the maximum number of operations that can be performed by removing two numbers at a time from the list while maintain
# Approach
<!-- Describe your approach to solving the problem. -->
The given code is designed to find the maximum number of operations that can be performed by removing two numbers at a time from the list while maintaining a sum condition. The solution follows a recursive backtracking with memoization approach.

# Understanding the Problem
* We are given an array nums[], and in each operation, we remove two elements whose sum is either:
1. The sum from the first operation (if it's the first step, we choose any two elements freely).
2. The same sum from all subsequent operations.
* The goal is to maximize the number of such operations.

# Key Observations
1. Since we are allowed to remove any two elements, the brute-force solution would involve trying all possible pairs.
2. To optimize, the algorithm tries three possible pairs in each recursive call:
--> First two elements (nums[0] and nums[1])
--> Last two elements (nums[n-1] and nums[n-2])
--> First and last element (nums[0] and nums[n-1])
3. If removing a pair results in a valid sum, we recursively call the function on the remaining array.
4. Memoization (store) is used to avoid recomputation of previously seen states.
# Breakdown of the Algorithm
1. Convert nums[] into an ArrayList to facilitate removal operations.
2. Recursive function finder():
--> Base Case: If nums is empty or has less than 2 elements, return 0.
--> Check if the current state (nums + sum) is already computed in store.
--> Try the three possible valid pairs and recursively find the maximum operations.
--> Restore the original list after recursion (backtracking step).
--> Store the result in store to avoid recomputation.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    HashMap<String, Integer> store;
    public int maxOperations(int[] nums) {
        ArrayList<Integer> collect = new ArrayList<>();
        store = new HashMap<>();
        for(int ele: nums){
            collect.add(ele);
        }
        return finder(collect, 0);
    }
    public int finder(ArrayList<Integer> nums, int sum){
        StringBuilder op = new StringBuilder();
        op.append(nums).append("-").append(sum);
        if(nums.isEmpty() || nums.size() < 2){
            return 0;
        }
        if(store.containsKey(op.toString())){
            return store.get(op.toString());
        }
        int ans = 0;
        if(sum == 0 || nums.get(0)+nums.get(1) == sum){
            int first0 = nums.get(0);
            int first1 = nums.get(1);
            nums.remove(0);nums.remove(0);

            ans = Math.max(ans, finder(nums, first0+first1)+1);

            nums.add(0, first0);nums.add(1, first1);
        }
        if(sum == 0 || nums.get(nums.size()-1)+nums.get(nums.size()-2) == sum){
            int last0 = nums.get(nums.size()-1);
            int last1 = nums.get(nums.size()-2);
            nums.remove(nums.size()-1);
            nums.remove(nums.size()-1);

            ans = Math.max(ans, finder(nums, last0+last1)+1);

            nums.add(last1);
            nums.add(last0);
        }
        if(sum == 0 || nums.get(0)+nums.get(nums.size()-1) == sum){
            int first = nums.get(0);
            int last = nums.get(nums.size()-1);
            nums.remove(nums.size()-1);
            nums.remove(0);

            ans = Math.max(ans, finder(nums, first+last)+1);

            nums.add(0, first);
            nums.add(last);
        }
        store.put(op.toString(), ans);
        return ans;
    }
}
```
['Array', 'Dynamic Programming', 'Memoization', 'Java']