Skip to content

Commit

Permalink
Determining the fewest number of coins needed to meet a given amount …
Browse files Browse the repository at this point in the history
…total.
  • Loading branch information
Tafara-N committed Aug 22, 2024
1 parent c0c0fd8 commit 44feaa2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion 0x08-making_change/0-making_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,20 @@ def makeChange(coins, total):
fewest number of coins needed to meet a given amount
"""

pass
if total <= 0:
return 0

coins.sort(reverse=True)
num_coins = 0

for coin in coins:
if total <= 0:
break

num_coins += total // coin
total %= coin

if total != 0:
return -1

return num_coins

0 comments on commit 44feaa2

Please sign in to comment.