Maximum Score From Removing Stones - Problem

You are playing a solitaire game with three piles of stones of sizes a, b, and c respectively.

Each turn you choose two different non-empty piles, take one stone from each, and add 1 point to your score. The game stops when there are fewer than two non-empty piles (meaning there are no more available moves).

Given three integers a, b, and c, return the maximum score you can get.

Input & Output

Example 1 — Balanced Case
$ Input: a = 2, b = 4, c = 6
Output: 6
💡 Note: We can take stones from different piles: (6,4), (5,3), (4,2), (3,2), (2,1), (1,1) → 6 moves total
Example 2 — Unbalanced Case
$ Input: a = 4, b = 4, c = 6
Output: 7
💡 Note: Total = 14, so max possible is 7. Two smaller piles sum to 8, so we can achieve 7 points
Example 3 — Large Pile Dominates
$ Input: a = 1, b = 8, c = 8
Output: 8
💡 Note: Limited by sum of two smaller piles: min(17/2, 1+8) = min(8, 9) = 8

Constraints

  • 1 ≤ a, b, c ≤ 105

Visualization

Tap to expand
Maximum Score From Removing Stones621Pile APile BPile CScore +1Take from 2 largest pilesOptimal StrategyAlways pick 2 largest pilesto maximize total movesMathematical Formula:min(total÷2, sum_of_two_smaller)= min(9÷2, 2+1) = min(4,3) = 3Maximum Score: 3
Understanding the Visualization
1
Input
Three piles with stones: a, b, c
2
Process
Each turn: pick 2 different non-empty piles, take 1 stone from each, +1 score
3
Output
Maximum possible score when game ends
Key Takeaway
🎯 Key Insight: Maximum score is limited by either total stones÷2 or sum of two smaller piles
Asked in
Google 15 Amazon 12 Microsoft 8
28.5K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen