Created
August 13, 2019 11:28
-
-
Save kaleidawave/4a5a6f5421d7f0f17977e794c1d49f19 to your computer and use it in GitHub Desktop.
The num of coins that are returned in change as mentioned in the first question of this interview https://www.youtube.com/watch?v=HWW-jA6YjHk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| coins = [25, 10, 5, 1] | |
| def num__of_coins(cents): | |
| if cents == 0: | |
| return 0 | |
| numOfCoins = 0 | |
| while cents > 0: | |
| for coin in coins: | |
| if cents >= coin: | |
| cents -= coin | |
| numOfCoins += 1 | |
| break | |
| return numOfCoins |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment