Back to Practice
#0271
Coin Change II
MediumDSA28 min20 XP
Problem
Given amount and coin denominations, return the number of combinations that sum to amount. Coin order does not matter.
Why This Matters
Coin Change II teaches the difference between combinations and permutations in DP loop order.
Function Signature
def coin_change_combinations(amount, coins):
Examples
Example 1
Inputamount = 5, coins = [1,2,5]
Output4
The combinations are 5, 2+2+1, 2+1+1+1, and five 1s.
Constraints
- Return the exact requested value.
- Handle edge cases cleanly.
- Use the intended DSA pattern when brute force would scale poorly.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 3 hidden categories
Four combinations
Inputamount = 5, coins = [1,2,5]
Expected4
Order does not create new combinations.
No combination
Inputamount = 3, coins = [2]
Expected0
You cannot make odd amount 3 using only coin 2.
Hidden Test Categories
amount zerocoin larger than amountmultiple coin sizes