MediumDynamic Programming· 64% acceptance
#766

Coin Change 16

Medium

Return the fewest coins needed to make `amount`, or `-1` if impossible. Variant **#16**.

Example 1

Input: coins = [1,2,5], amount = 21

Output: 5

Constraints

  • 1 <= coins.length <= 12
  • 0 <= amount <= 10^4

Acceptance: 64% · Topics: dynamic-programming, bfs

coinChange

← All practice problems