Back to Practice Dashboard
Competitive ProgrammingEasy
Minimum number of coins
Learn how to solve the 'Minimum number of coins' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Write a function min_coins(coins, V) that returns the minimum number of coins needed to make a target change V using the given coin denominations coins. If it is impossible to make change, return -1.
Constraints
- •1 <= len(coins) <= 100
- •1 <= V <= 10000
- •1 <= coins[i] <= 1000
Examples
Example 1
Input
min_coins([9, 6, 5, 1], 11)
Output
2
Explanation
We can make 11 using coins 6 and 5 (2 coins).
Example 2
Input
min_coins([5, 10], 7)
Output
-1
Explanation
We cannot make change for 7 using only coins of value 5 and 10.
Need a Hint?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.