Coin Change - Fewest Coins For Amount - aloalgo

Coin Change - Fewest Coins For Amount

Medium

You are given an array of integers coins representing coin denominations and an integer amount.

Your task is to determine the minimum number of coins required to reach amount.

You may assume that:

  • You have an infinite number of each kind of coin.

Return the minimum number of coins needed. If the amount cannot be formed by any combination of coins, return -1.

Example 1

Inputs
coins = [1, 5, 10, 25]
amount = 11
Output
2
Explanation:

The amount 11 can be made with one 10-coin and one 1-coin.

Example 2

Inputs
coins = [5, 10, 25]
amount = 3
Output
-1
Explanation:

The amount 3 cannot be made with the given coin denominations.

Example 3

Inputs
coins = [1, 5, 10, 25]
amount = 0
Output
0
Explanation:

Zero coins are needed to make an amount of 0.

Loading...
Inputs
coins = [1, 5, 10, 25]
amount = 11
Output
2

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!