Easiest Explaination (You Won't Regret) Line by Line
IntuitionAs given in the question we have to perform the operation till the sum is same for all operation .Now in starting we have 3 choices
delete the first tw
# Intuition
#### As given in the question we have to perform the operation till the sum is same for all operation .
##### Now in starting we have 3 choices 
1. delete the first two ,sum will be nums[0]+nums[1];
2. delete the last two , sum will be nums[n-1]+nums[n-2]
3. delete the first one and last one ,sum will be nums[0]+nums[n-1]

### Now you must have to perform 1 of the above 3 operations at starting
##### so there are only 3 values of sum are possible 

###### Now try one by one for all 3 values,continue till the condition remains satisfied or starting<ending(as all values will be deleted if starting==ending or starting>ending),then at last return max of all three possiblilies +1
###### +1(as we have already performed one operation during sum selection)

# Approach
##### READ INTUTION ,YOU WILL UNDERSTAND ALL OF IT 
###### try all sum possibilities as i have done in the main then return max of all three posibilities +1

In Recursion:-
###### There will be four parameters starting index,ending index,nums,sum value
If(s==e)return 0 as all array is traversed
Initialize the variable c=0 to count the operations
Then try all three posibilities one by one and at each call add 1 to c (1 operation completed)
Also i have added checks at each rec call to check weather the remaining array have sufficient elements to perform operations.

Now at last to avoid overlapping sub-problems I have declared 2d dp(two parameters are changing starting and endind index) set all values to -1 initially.
Initialized it with the max possible size of starting and ending index.
Now at each call before returning I saved that ans to my dp array.
At each rec call I will check weather i have solved it previously if yes then no need to solve furthur.

# Complexity
- Time complexity: o(n^2)
-Each recursive call reduces the size of the subproblem, and there are a constant number of recursive calls. Therefore, the time complexity of each recursive call is O(1).
There are a total of n^2 subproblems (since there are two parameters s and e ranging from 0 to n-1). For each subproblem, the solution is computed in O(1) time. Hence, the overall time complexity is O(n^2).

- Space complexity: o(n)

# Code
```
class Solution {
public:
    int t[2001][2001];
    int solve(int s,int e,vector<int>&nums,int sum){ 
        if(s>=e){
            return 0;
        }
        if(t[s][e]!=-1){
             return t[s][e];
        } 
        int c=0;
        if(nums[s]+nums[e]==sum){
              c=1+solve(s+1,e-1,nums,sum);
        }
        if(s+2<=e && nums[s]+nums[s+1]==sum){
            c=max(c,solve(s+2,e,nums,sum)+1);
        }
        if(e-2>=s&& nums[e]+nums[e-1]==sum){
            c=max(c,solve(s,e-2,nums,sum)+1);
        }
        return t[s][e]=c;

    }
    int maxOperations(vector<int>& nums) {
        int n=nums.size();
        memset(t,-1,sizeof(t));
        int case1=nums[0]+nums[1];        // CASE 1
        int k=solve(2,n-1,nums,case1);
        int case2=nums[n-1]+nums[n-2];    // CASE 2
        int l=solve(0,n-3,nums,case2);
        int case3=nums[0]+nums[n-1];      // CASE 3
        int p=solve(1,n-2,nums,case3);
        return 1+max({k,l,p});
    }
};
```
UPVOTE :)
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']