Paths Subjects Questions Quizzes Pricing Search
Intermediate Open Pro

Minimum Coin Combination

You are given an array of integers coins representing coin denominations (in unlimited supply) and an integer amount. Return the fewest number of coins needed to make up exactly amount. If that amount cannot be made up by any combination of the coins, return -1.

Example 1

Input: coins = [1, 3, 4], amount = 6
Output: 2
Explanation: 6 = 3 + 3, using 2 coins.

Example 2

Input: coins = [2], amount = 3
Output: -1
Explanation: 3 cannot be made using only coins of value 2.

Constraints

  • 1 <= coins.length <= 12
  • 1 <= coins[i] <= 2^31 - 1
  • 0 <= amount <= 10^4

Share this question

← Back to Dynamic Programming practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.