Skip to main content

Practice · 1 of 5

Coin Change (Canonical)

CHALLENGE
Difficulty: beginner+25 XP

**Description:** With unlimited coins of 1, 5, 10, 20, 50, 100, 200, 500, pay exactly X using the fewest coins. Print the coin count. **Input:** One integer X (1 ≤ X ≤ 10^9). **Output:** One integer — the minimum number of coins. **Example:** 60 → 3 (50 + 10); 763 → 8 (500+200+50+10+... check: 500+200 = 700, +50 = 750, +10 = 760, +1·3 = 763 → 3+3... compute: 500, 200, 50, 10, 1, 1, 1 → 7 coins).

Back to lesson: Practice: Greedy Set