Python "Numpy Is The King" solution (Runtime: 220 ms)
Just the same bottom-up solution as any other. But much faster with numpy:\n\n\nimport numpy as np\n\nclass Solution:\n    def stoneGameVII(self, stones: List[i
Just the same bottom-up solution as any other. But much faster with numpy:\n\n```\nimport numpy as np\n\nclass Solution:\n    def stoneGameVII(self, stones: List[int]) -> int:\n        n = len(stones)\n        stones = np.array(stones, dtype = int)\n        score = np.zeros(n, dtype = int)\n        summ = np.array(stones, dtype = int)\n        for l in range(1, n):\n            nxt = np.maximum(summ[:n-l]-score[:n-l], summ[1:n-l+1]-score[1:n-l+1])\n            summ[:-l] += stones[l:]\n            score = nxt\n        \n        return score[0]\n```\nThis is usual bottom-up approach: we start with n lines of stones of len 1 (starting at positions 0..n-1), and calculate for them score and sum. Score for them is 0 and sum is every stone. Then we are doing the same with (n-1) lines of len 2, and so on up to 1 line of len n. For every line of len m starting in in dex i the score in max of: sum(all stones except right) - score(of line of len m-1 starting at i) OR sum(all stones except left) - score(of line of len m-1 starting at i+1).\n\nAnd when we got to line of len n - this is our answer.\n\nThe speed comes from numpy using vector SIMD instructions. It is not the easiest thing to read and write, but works fast. Line `summ[:-l] += stones[l:]` for example adds one more stone to every position from 0 to -l and can be writen as equivalent cycle:\n```\nfor i in range(0, n-l):\n\t\tsumm[i] += stones[i+l]\n```\nBut in numpy it doesn\'t make this summs one by one. Its doing it in batches (or vectors) of up to 512 variables at ones.
[]