Minimum number of coins
Detailed guide and Python implementation for the 'Minimum number of coins' problem.
Problem Statement
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.
- •1 <= len(coins) <= 100
- •1 <= V <= 10000
- •1 <= coins[i] <= 1000
Examples
min_coins([9, 6, 5, 1], 11)
2
We can make 11 using coins 6 and 5 (2 coins).
min_coins([5, 10], 7)
-1
We cannot make change for 7 using only coins of value 5 and 10.
Need a Hint?
Edge Cases to Watch
- Empty input structures
- Single element inputs
- Large numerical bounds
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Find the Length of a List in Python
Learn how to find the length of a list in Python using the len() function. Understand the O(1) time complexity and checking counts.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.