Solution: Money Change

Solutions for the Money Change Problem using a greedy approach.

Solution 1: Use the largest denomination first

Here is the idea: while moneymoney > 00, we keep taking a coin with the largest denomination that does not exceed moneymoney, subtracting its value from moneymoney, and adding 11 to the count of the number of coins:


 Change(money)Change(money):
 numCoinsnumCoins \leftarrow 0
 while moneymoney >> 0:
  if moneymoney 10:
   moneymoney \leftarrow moneymoney 1010
  else if moneymoney ...