📚 PracticeMediumAlgorithm ProblemCoding Ready

Coin Change

dynamic-programmingarraybfs
LeetCode #322
Updated Dec 20, 2025

Question

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

LeetCode: Coin Change

Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

You may assume that you have an infinite number of each kind of coin.

Example:

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

Input: coins = [2], amount = 3
Output: -1
Explanation: Cannot make 3 with only coin of denomination 2

Input: coins = [1], amount = 0
Output: 0

Hints

Hint 1

Think about building up from smaller amounts. If you know the minimum coins needed for amount i, how do you compute it for amount i+1?

Hint 2

For each amount, try using each coin. The answer is 1 + the minimum coins needed for (amount - coin).

Hint 3

Initialize dp array with infinity except dp[0] = 0. This helps you handle impossible cases.


Your Solution

python
Auto-saves every 30s

Try solving the problem first before viewing the solution


0:00time spent