Count Unordered Combinations of Unlimited Coins
Company: Worldquant
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: Count distinct ways to reach a target with unlimited coins, treating different orders of the same denominations as one combination.
Constraints
- 0 <= len(coins) <= 100
- Every denomination is an integer from 1 through 10000
- Denominations are distinct, and the input order may be arbitrary
- 0 <= target <= 100
- The count fits a signed 32-bit integer under these bounds
- There is one way to make a target of zero: choose no coins
- With no denominations, a positive target has zero combinations
- Each denomination may be used an unlimited number of times
- Combinations are unordered: two selections using the same coins in a different order are the same combination
Examples
Input: ([], 0)
Expected Output: 1
Explanation: No denominations and a target of zero: the single combination is the empty selection, so the answer is 1.
Input: ([1, 2, 5], 0)
Expected Output: 1
Explanation: A target of zero is made exactly one way regardless of which denominations are available: choose no coins.
Hints
- The same multiset of coins can be assembled in several sequences. Choose a state progression that counts each multiset once rather than once per sequence.
- The statement already fixes the answer for a target of zero; make that the base case of whatever progression you build up from.
- A denomination larger than the target can never appear in any combination, so it cannot affect the answer.