Problem statement

https://binarysearch.com/problems/Three-Player-Coin-Game/

Solution

Equal to Leetcode 1561. Maximum Number of Coins You Can Get.

Complexity

It is O(n log n) for time and O(n) for space.

Code

class Solution:
    def solve(self, A):
        A = sorted(A)
        n = len(A)
        return sum(A[n//3::2])