Greedy Algorithms · Coding problem

Minimum Coins to Make Sum

A free coding problem from the Greedy Denomination Coins skill. Read it here, then solve it in the app in Java or Python.

  • Easy
  • Coding problem
  • Free
  • Java and Python

The problem

A cash drawer holds euros - the 1 and 2 euro coins and the 5 to 200 euro notes, so the values {1, 2, 5, 10, 20, 50, 100, 200} - as many of each as you need. Return the fewest pieces that add up to exactly amount.

Example

Input:  amount = 286
Output: 6

200 + 50 + 20 + 10 + 5 + 1 = 286, six pieces.

Constraints

  • 0 <= amount <= 10^9

How it's graded

  • Run checks your code against the examples. Submit also runs a hidden suite in four groups - basic cases, edge cases, random inputs and performance tests at the size limit - and shows which groups pass, never the hidden inputs.
  • Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.
  • Once you pass, you see the approaches from brute force to optimal, and where your solution lands among them.

More problems in Greedy Denomination Coins

Solve it Minimum Coins to Make Sum free

No card needed. Lessons, practice questions and easy problems are free forever.

Free plan, no card · 7-day Pro trial · Cancel anytime