Problem
You get an integer amount and an integer array coins. Each item in coins is the value of one type of coin. You have an unlimited number of coins of each type.
Return the number of combinations of coins that add up to exactly amount. If no combination adds up to amount, return 0.
A combination is a group of coins. The order of the coins in a group does not matter. So 1 + 2 and 2 + 1 are the same combination.
The answer fits in a signed 32-bit integer.
Example 1
- Input:
- amount = 6, coins = [1,3,4]
- Output:
- 4
- Explanation:
- The combinations are
3 + 3,4 + 1 + 1,3 + 1 + 1 + 1and1 + 1 + 1 + 1 + 1 + 1.
Example 2
- Input:
- amount = 5, coins = [2,4]
- Output:
- 0
- Explanation:
- Each sum of coins with the values 2 and 4 is an even number. The amount 5 is odd.
Example 3
- Input:
- amount = 0, coins = [7]
- Output:
- 1
- Explanation:
- The empty combination has no coins, and its sum is 0.
Constraints
- 1 <= coins.length <= 300
- 1 <= coins[i] <= 5000
- All the values in coins are different.
- 0 <= amount <= 5000
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Coin Change
Coding · Array · Breadth-First Search · Complete Knapsack
- Inverse Coin Change
Coding
- Change Data Type
Coding
- Change Directory
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
Pinterest
Leetcode 518. Coin Change II
Reported Mar 16, 2026 · 2 source reports
MID_LEVEL
Source snapshot: Nov 12, 2026
View source