Back to Practice
#0168
Coin Change Minimum Coins
MediumDSA25 min20 XP
Problem
Given coin denominations and an amount, return the minimum number of coins needed. Return -1 if impossible.
Why This Matters
Coin change teaches how DP reuses smaller answers instead of recursively trying every combination.
Function Signature
def coin_change(coins, amount):
Examples
Example 1
Inputcoins = [1, 2, 5], amount = 11
Output3
11 can be made with 5 + 5 + 1.
Constraints
- Return the exact requested output.
- Handle ordinary edge cases.
- Prefer simple, interview-readable code.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputcoins = [1, 2, 5], amount = 11
Expected3
11 can be made with 5 + 5 + 1.
Hidden Test Categories
empty or minimal inputduplicates or tieslarger input