Maximum Number of Coins You Can Get

There are 3n piles of coins. Repeatedly choose any 3 piles: Alice takes the largest, you take the next largest, and Bob takes the last one. Continue until no piles remain. Given piles, return the maximum number of coins you can have.

30:00

Maximum Number of Coins You Can Get
medium
Free written solution
Topics
Companies

There are 3n piles of coins. Repeatedly choose any 3 piles: Alice takes the largest, you take the next largest, and Bob takes the last one. Continue until no piles remain. Given piles, return the maximum number of coins you can have.

Example 1:
Input: {"piles":[2,4,1,2,7,8]}
Output: 9
Constraints:
  • 3≤piles.length≤1053 \leq \text{piles.length} \leq 10^5

  • piles.length mod 3=0\text{piles.length} \bmod 3 = 0

  • 1≤piles[i]≤1041 \leq \text{piles}[i] \leq 10^4

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"piles":[2,4,1,2,7,8]}

6 piles, so 2 rounds of three. Alice always grabs the biggest pile of a triple and Bob the smallest, so you want every triple to be "two big piles plus one tiny one".

Bob

0

you

0

Alice

0

piles, as given

241278
Variables
No variables to display
DepthFunction Call
Stack empty
0/4