C++ Simple & Easy Solution (memoization)
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```cpp []
class Solution {
public:
    int maxOperations(vector<int>& nums) {
        int len = nums.size();

        vector<vector<int>> m(len, vector<int>(len, 0));
        
        function<int(int, int, int)> dfs = [&](int s, int e, int score) -> int {
            if (s >= e) return 0;

            if (m[s][e]) return m[s][e];

            int cnt = 0;
            if (s+1 < len && score == nums[s] + nums[s+1]) 
                cnt = max (cnt, dfs(s+2, e, score) + 1);
            if (score == nums[s] + nums[e]) 
                cnt = max (cnt, dfs(s+1, e-1, score) + 1);
            if (e-1 >= 0 && score == nums[e-1] + nums[e]) 
                cnt = max (cnt, dfs(s, e-2, score) + 1);

            return m[s][e] = cnt;
        };

        
        int ans = 0;
        ans = max(ans, dfs(2, len-1, nums[0] + nums[1])+1);
        ans = max(ans, dfs(1, len-2, nums[0] + nums[len-1])+1);
        ans = max(ans, dfs(0, len-3, nums[len-2] + nums[len-1])+1);
        return ans;
    }
};
```
['C++']