Ways to Make Change
Given distinct coin values coins (each usable any number of times) and a target amount, return the number of different combinations of coins that add up to exactly amount. The order of coins does not matter, so 1+2 and 2+1 are the same combination. For amount = 0 the answer is 1.
Example 1
coins [1,2,5]
amount 5
returns 4
5, 2+2+1, 2+1+1+1 and 1+1+1+1+1.
Constraints
1 <= len(coins) <= 51 <= coins[i] <= 250 <= amount <= 30
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.