c++ recursion + memoization
class Solution  {\npublic: \n    int dp[1001][1001];\n    int solve(vector<int>&a,int i,int j,int sum)\n    {\n        //base case\n        if(i>j)return 0;\n  
```class Solution  {\npublic: \n    int dp[1001][1001];\n    int solve(vector<int>&a,int i,int j,int sum)\n    {\n        //base case\n        if(i>j)return 0;\n        if(dp[i][j]!=-1)return dp[i][j];\n        return dp[i][j]= max(sum-a[i]-solve(a,i+1,j,sum-a[i]) , sum - a[j] - solve(a,i,j-1,sum-a[j]));\n        return dp[i][j];\n    }\n    int stoneGameVII(vector<int>& a) {\n        int n=a.size();\n       // int lsum[n] , rsum[n];\n       int sum = 0 ;\n        for(int i=0;i<n;i++)\n            sum += a[i];\n        memset(dp,-1,sizeof(dp));\n      return solve(a,0,n-1,sum);\n    }\n};```
[]