C++ Easy Solution | Memoization | 3 ms Beats 100.00%
Code\n\nclass Solution {\n    int findSol(vector<int> &a,int tar,int st,int en,unordered_map<string,int> &m){\n        if(st>=en) return 0;\n        string temp
# Code\n```\nclass Solution {\n    int findSol(vector<int> &a,int tar,int st,int en,unordered_map<string,int> &m){\n        if(st>=en) return 0;\n        string temp = to_string(st)+" "+to_string(en)+" "+to_string(tar);\n        if(m.count(temp)) return m[temp];\n        if(en-st>=3){\n            if(a[st]+a[st+1]==tar&&a[en]+a[en-1]==tar){\n                m[temp] =  findSol(a,tar,st+2,en-2,m)+2;\n                return m[temp];\n            }\n        }\n        int ans =0 ;\n        if(a[st]+a[st+1]==tar) ans = max(ans,findSol(a,tar,st+2,en,m)+1);\n        if(a[st]+a[en]==tar) ans = max( ans, findSol(a,tar,st+1,en-1,m)+1);\n        if(a[en]+a[en-1]==tar) ans = max(ans,findSol(a,tar,st,en-2,m)+1);\n        m[temp] = ans;\n        return ans;\n    }\npublic:\n    int maxOperations(vector<int>& a) {\n        int n = a.size() ;\n        unordered_map<string,int> m;\n        int ans1 = findSol(a,a[0]+a[1],2,n-1,m)+1;\n        int ans2 = findSol(a,a[0]+a[n-1],1,n-2,m)+1;\n        int ans3 = findSol(a,a[n-1]+a[n-2],0,n-3,m)+1;\n        return max({ans1,ans2,ans3});\n    }\n};\n```
['C++']