AlgoFrames

Fill the coin table

Warm-up · Trace the algorithm · about 5 min

Coins 1, 2 and 5 make amounts up to 7. Follow the fewest-coins table and answer each question before the step plays.

Example 1

Input:

{"coins":[1,2,5],"amount":7}

Output:

2

Constraints

  • The trace uses the coins shown.
  • Each coin may be used any number of times.

Learn the idea first: Coin change: minimum coins and number of ways, a visual lesson.

More Coin change: minimum coins and number of ways problems