Problems

23. Coin Change

MediumDynamic ProgrammingAmazonMicrosoft

Given coin denominations and an amount, return the minimum number of coins needed, or -1 if the amount cannot be formed.

Example 1:

Input: coins = [1,2,5], amount = 11
Output: 3

Example 2:

Input: coins = [2], amount = 3
Output: -1

Constraints:

  • 1 <= coins.length <= 12
  • 0 <= amount <= 10^4
Core code mode
● Auto-savedLine 1, column 1