[Python] O(n^2) Accepted Submission (with comments)
\nclass Solution:\n    def stoneGameVII(self, stones: List[int]) -> int:\n        n = len(stones)\n        if n==0:\n            return 0\n        total = sum(s
```\nclass Solution:\n    def stoneGameVII(self, stones: List[int]) -> int:\n        n = len(stones)\n        if n==0:\n            return 0\n        total = sum(stones)\n        \n        dp = [[-1]*n for _ in range(n)]\n        ##Maximum difference the current player can achieve when stones[i:j](included) are left\n        ##Curr is sum of all stones[i:j]\n        def helper(i, j, curr):\n            if i>=j:\n                return 0\n            if dp[i][j] != -1:\n                return dp[i][j]\n             ##The player picks ith stone and with remaining stones other player tries to maximize the difference from his/her perspective\n            opt1 = (curr - stones[i]) - helper(i+1, j, curr-stones[i])\n             ##The player picks jth stone and with remaining stones other player tries to maximize the difference from his/her perspective\n            opt2 = (curr - stones[j]) - helper(i, j-1, curr-stones[j])\n            dp[i][j] = max(opt1, opt2)\n            return dp[i][j]\n        \n        return helper(0, n-1, total)\n```
[]