Go | DP | Beat 100%
\nfunc stoneGameVII(stones []int) int {\n    sum := buildPrefixSum(stones) \n    \n    var (\n        prev, current [2][]int\n        n = len(stones)\n    )\n  
```\nfunc stoneGameVII(stones []int) int {\n    sum := buildPrefixSum(stones) \n    \n    var (\n        prev, current [2][]int\n        n = len(stones)\n    )\n    \n\t// prev and current is pivot dp slice which store difference of each state\n\t//\n\t// 0: Alice move\n\t// 1: Bob move\n    prev[0], prev[1] = make([]int, n), make([]int, n)\n    current[0], current[1] = make([]int, n), make([]int, n)\n   \n    for ln := 2; ln <= n; ln++ {\n        for i := 0; i <= n - ln; i++ {\n            s1 := rangeSum(sum, i, i + ln - 2)\n            s2 := rangeSum(sum, i + 1, i + ln - 1)\n            \n\t\t\t// 0: Alice move -> try to maximize the difference, she knows that next move is Bob\n            current[0][i] = max(prev[1][i] + s1, prev[1][i+1] + s2)\n\t\t\t\n\t\t\t// 1: Bob move -> try to minimize the difference, he knows that next move is Alice\n            current[1][i] = min(prev[0][i] - s1, prev[0][i+1] - s2)\n        }\n        \n        prev, current = current, prev\n    } \n    \n    return prev[0][0]\n}\n\nfunc buildPrefixSum(v []int) (sum []int) {\n    sum = make([]int, len(v))\n    \n    s := 0\n    for i := range v {\n        s += v[i] \n        sum[i] = s\n    }\n    \n    return\n}\n\n// inclusive\nfunc rangeSum(prefixSum []int, from, to int) int {\n    if from == 0 {\n        return prefixSum[to]\n    }\n    return prefixSum[to] - prefixSum[from - 1]\n}\n\nfunc min(a, b int) int {\n    if a < b {\n        return a\n    }\n    return b\n}\n\nfunc max(a, b int) int {\n    if a > b {\n        return a\n    }\n    return b\n}\n```
['Go']