Animate the greedy coin change algorithm. Watch how picking the largest coin at every step finds the minimum number of coins for canonical systems.
About this algorithm
Greedy coin change makes an amount using as few coins as it can by always taking the largest coin that still fits. It is what a cashier does when handing back change: as many of the biggest coin as possible, then the next one down, and so on. It is fast and needs no table, but it only gives the fewest coins for certain coin systems.
Use the greedy method when the coin system is canonical, meaning greedy is known to give the fewest coins for every amount. US coins (25, 10, 5, 1), euro coins and Indian rupee coins are all like this. For any other set of coins, or when you do not know, use the dynamic programming coin change method, which tries every coin at every amount and is always right. Greedy is a good first answer in an interview only if you then explain where it breaks.
The biggest coin is tried first.
Divide the remaining amount by the coin value and round down. That many coins go in the answer, and the remaining amount drops by that many times the coin value.
If a coin is bigger than what is left, it contributes nothing; skip it.
When the remaining amount reaches zero, the coins taken are the answer. If the smallest coin is not 1, some amounts may be left over and cannot be made.
The page makes 36 from coins of 25, 10, 5 and 1. One 25 fits, leaving 11. One 10 fits, leaving 1. The 5 is bigger than 1, so it is skipped. One 1 finishes the job. The answer is 25 + 10 + 1, three coins, and for US coins that is the fewest possible.
With coins 1, 3 and 4, make 6. Greedy takes a 4, then cannot use a 3 on the remaining 2, so it adds 1 and 1: three coins. Two 3s make 6 with only two coins. Taking the biggest coin first threw away a better split. The dynamic programming coin change page loads exactly this case and finds the two-coin answer by building up the best count for every amount from 0 to 6.
Time: each of the m coin types is visited once with one division, so the work does not depend on the size of the amount; sorting the coins first adds m log m. Space: only the remaining amount and the count per coin type are kept.