kotlin - dp using memo
\n    fun stoneGameVII(stones: IntArray): Int {\n        val sum = stones.sum()\n        val memo = Array(stones.size){IntArray(stones.size){-1} }\n        retu
```\n    fun stoneGameVII(stones: IntArray): Int {\n        val sum = stones.sum()\n        val memo = Array(stones.size){IntArray(stones.size){-1} }\n        return play(stones, 0, stones.lastIndex, sum, memo)\n    }\n\n    fun play(stones: IntArray, l:Int, r: Int, sum: Int, memo: Array<IntArray>) : Int {\n        if(l == r) return 0\n        if (memo[l][r] != -1) return memo[l][r]\n        val a = sum - stones[l] - play(stones, l+1, r, sum - stones[l], memo)\n        val b = sum - stones[r] - play(stones, l, r-1, sum - stones[r], memo)\n        memo[l][r] = maxOf(a, b)\n        return memo[l][r]\n    }\n```
[]