Skip to content

Practice Maximum Number of Coins You Can Get

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1561
LeetCode Problem

Maximum Number of Coins You Can Get

Problem Statement

There are 3n coin piles. Repeatedly choose any three remaining piles: Alice receives the largest, you receive the next largest, and Bob receives the last. Continue until every pile is taken. Choose the groups to maximize your total coins and return that total.

Source: Maximum Number of Coins You Can Get on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
piles = [2,4,1,2,7,8]
Output
9

# Example 2

Input
piles = [2,4,5]
Output
4

# Example 3

Input
piles = [9,8,7,6,5,1,2,3,4]
Output
18

Constraints

3 <= piles.length <= 10^5
piles.length % 3 == 0
1 <= piles[i] <= 10^4

Related LeetCode Problems

Practice more problems similar to Maximum Number of Coins You Can Get.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.