C++ Solution || DP || Easy Understanding
\nclass Solution {\npublic:\n    int helper(int l, int r, vector<int>& stones, int sum, vector<vector<int>>& dp){\n        if(l == r) return 0; //array has 1 el
```\nclass Solution {\npublic:\n    int helper(int l, int r, vector<int>& stones, int sum, vector<vector<int>>& dp){\n        if(l == r) return 0; //array has 1 element\n        if(r-l == 1) return max(stones[l], stones[r]); // array has 2 elements\n        if(dp[l][r] != -1) return dp[l][r]; //memorization\n        int left_remove = sum - stones[l] - helper(l+1, r, stones, sum-stones[l], dp);\n        int right_remove = sum - stones[r] - helper(l, r-1, stones, sum-stones[r], dp);\n        return dp[l][r] = max(left_remove, right_remove);\n    }\n    int stoneGameVII(vector<int>& stones) {\n        int n = stones.size(), sum = 0;\n        vector<vector<int>>dp(n,vector<int>(n, -1));\n        for(int i = 0; i < n; i++) sum += stones[i];\n        return helper(0, n-1, stones, sum, dp);\n    }   \n};\n```
['Dynamic Programming', 'C', 'C++']