ebosetalee / 20-days-challenge

#20dayschallenge on python
6 stars 0 forks source link

3b - Count Change #7

Closed jirevwe closed 4 years ago

jirevwe commented 4 years ago

Write a function countChange(amount, [...denominations]) that counts the number of ways you can make change for an amount of money, given an array of coin denominations.

For example, there are 3 ways to give change for 4 if you have coins with denomination 1 and 2:

1+1+1+1
1+1+2
2+2

The order of the coins doesn’t matter.

1+1+2 == 1+2+1 == 2+1+1

Also, assume you have an infinite amount of coins.

Your function should take an amount to change and an array of unique denominations for the coins.

countChange(4, [1, 2]) // will return 3
countChange(10, [2, 3, 5]) // will return 4
countChange(11, [5, 7]) // will return 0