medium2-D Dynamic ProgrammingAmazon
Combo Coin Counter
An accountant counts the distinct combinations of unlimited-stock coin denominations that total an exact amount.
Given coins of different denominations and amount, return the number of combinations that make that amount.
Choose approach
1
?
?
?
?
?
1
?
?
?
?
?
1
?
?
?
?
?
1
?
?
?
?
?
1/5
Narrationstep 1 of 5
Seed first column with 1 (one way to make 0).
Variables
amount=5
coins=1,2,5
How to think about it
- Reversed loop order would count permutations, not combos.
- Equivalent 2-D form dp[i][a] shown here.
Edge cases to catch in interview
- amount=0 -> 1.
- No coin divides anything -> 0.
Examples
Example 1
0{"amount":3,"coins":[2]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed