Competitive Programming簡単

Minimum number of coins

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

問題提起

簡単

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

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

解決する準備はできましたか?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

エディタで開く
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推奨される Python リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。