Coin Change II
Updated
Problem statement
The array coins contains different coin values. You have an unlimited supply of coins of each value. Count the combinations that sum to amount.
The order of the coins does not make a different combination: using coins 1,2,2 is the same combination as using 2,1,2. Return 0 when no combination exists. Amount 0 has one combination, the empty selection.
The requested count fits in a signed 32-bit integer.
Function
change(amount: int, coins: int[]) → intExamples
Example 1
amount = 5coins = [1,2,5]return = 4The amount can be made as [5], [2,2,1], [2,1,1,1], or [1,1,1,1,1]. No other combination works, so the answer counts these combinations.
Example 2
amount = 3coins = [2]return = 0Every coin is worth 2, so any total you can build is even. The amount is odd, so there are no combinations at all.
Example 3
amount = 10coins = [10]return = 1A single coin worth 10 makes the amount. That is the only combination, so the answer counts just this one.
Constraints
1 <= coins.length <= 300.- All coin values are different, with
1 <= coins[i] <= 5000. 0 <= amount <= 5000.- The answer is at most
2^31 - 1.
More Apple Phone Screen questions
- Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Count Winning Electoral-State CoalitionsGoogle · ONSITE INTERVIEWGoogle interview questions
- Winning Draws for a Mahjong HandZip · PHONE SCREENZip interview questions
- Count Strictly Increasing Subsequences of Length 3IBM · OAIBM interview questions
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
- Count Good SubsequencesFlexport · OAFlexport interview questions
- Sum of Compressed Number for All SubarraysWells Fargo · OAWells Fargo interview questions
- Count Perfect BreaksAtlassian · OAAtlassian interview questions
- Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
- Maximum Subarray Sum with One DeletionServiceNow · PHONE SCREENServiceNow interview questions