Competitive ProgrammingEasy

Minimum number of coins

Detailed guide and Python implementation for the 'Minimum number of coins' problem.

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?
Consider using Dynamic Programming-specific data structures like sets or heaps.
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.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.