On this page
Coin Change
Solving Coin Change using Unbounded knapsack.
Problem
Minimum coins for amount.
Pattern
This problem demonstrates the Unbounded knapsack pattern.
Approach
Bottom-up DP over amounts.
Solution
// Solution for Coin Change
// Pattern: Unbounded knapsack
// O(amount × coins) time
Complexity
O(amount × coins) time
Best Practices
- Identify the pattern before coding — pattern recognition saves time
- Handle edge cases: empty input, single element, duplicates
- Use descriptive variable names even in timed interviews
- Test with the provided examples plus one custom case