← All problems

Coin Change

Medium dynamic programming LeetCode ↗
Given coin denominations and a target amount, find the fewest coins needed to make up that amount; return -1 if it is impossible. You may use each denomination any number of times.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(amount * coins), Space O(amount)

Common pitfalls

  • Greedy coin choice
  • Wrong loop order confusion with counting variant

Your solution

Log in to save your code and track progress.