SImple C++ solution | O(n*n)
\nclass Solution {\npublic:\n    \n    int dfs(vector<int> &stones, int i, int j, int sum){\n        \n        //Because after removing you will not get anythin
```\nclass Solution {\npublic:\n    \n    int dfs(vector<int> &stones, int i, int j, int sum){\n        \n        //Because after removing you will not get anything because ntohing is left in the array.\n        if(i==j) return 0;\n        \n        if(dp[i][j]) return dp[i][j];\n        // dp[i][j] -> stores the difference\n        int left_removed = sum - stones[i] - dfs(stones, i+1, j, sum - stones[i]);\n        int right_removed = sum - stones[j] - dfs(stones, i, j-1, sum - stones[j]);\n        return dp[i][j] = max(left_removed, right_removed);\n    }\n    \n    int dp[1001][1001] = {};\n    int stoneGameVII(vector<int>& stones) {\n       int n = stones.size();\n        int sum = 0;\n        for(int i=0;i<n;i++){\n            sum += stones[i];\n        }\n        \n        return dfs(stones, 0,n-1,sum);\n    }\n};\n```
[]