Skip to main content

Coin Change

MediumDynamic Programming

Given an array of coin denominations coins and a total amount, return the minimum number of coins needed to make up that amount. If it's not possible, return -1.

Example:

Input: coins = [1,5,10], amount = 11
Output: 2
Explanation: 11 = 10 + 1, so 2 coins

Constraints:

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