Watch 4 video solutions for Kth Smallest Amount With Single Denomination Combination, a hard level problem involving Array, Math, Binary Search. This walkthrough by Aryan Mittal has 7,766 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
You are given an integer array coins representing coins of different denominations and an integer k.
You have an infinite number of coins of each denomination. However, you are not allowed to combine coins of different denominations.
Return the kth smallest amount that can be made using these coins.
Example 1:
Input: coins = [3,6,9], k = 3
Output: 9
Explanation: The given coins can make the following amounts:
Coin 3 produces multiples of 3: 3, 6, 9, 12, 15, etc.
Coin 6 produces multiples of 6: 6, 12, 18, 24, etc.
Coin 9 produces multiples of 9: 9, 18, 27, 36, etc.
All of the coins combined produce: 3, 6, 9, 12, 15, etc.
Example 2:
Input: coins = [5,2], k = 7
Output: 12
Explanation: The given coins can make the following amounts:
Coin 5 produces multiples of 5: 5, 10, 15, 20, etc.
Coin 2 produces multiples of 2: 2, 4, 6, 8, 10, 12, etc.
All of the coins combined produce: 2, 4, 5, 6, 8, 10, 12, 14, 15, etc.
Constraints:
1 <= coins.length <= 151 <= coins[i] <= 251 <= k <= 2 * 109coins contains pairwise distinct integers.Problem Overview: You are given several coin denominations. You can use only one denomination at a time but any number of coins of that type. Each denomination generates multiples (d, 2d, 3d...). The task is to find the kth smallest amount that appears in the union of all these multiples.
Approach 1: Min-Heap Approach for Multiples (O(k log n) time, O(n) space)
Treat every denomination as an infinite sorted sequence of multiples. Start by pushing the first multiple of each denomination into a min-heap. Repeatedly pop the smallest value, record it if it is not a duplicate, and push the next multiple of the same denomination. A hash set or last-seen value helps avoid counting duplicates when two denominations produce the same amount (for example 6 from 2×3 and 3×2). This approach mirrors merging k sorted lists. It works well when k is moderate, but performance degrades for very large k because you must explicitly generate values one by one.
Approach 2: Mathematical Counting with Binary Search (O(2^n log R) time, O(1) space)
The optimal strategy avoids generating values directly. Instead, binary search the answer x. For each candidate value, compute how many valid amounts are ≤ x. Every denomination contributes x / coin multiples, but overlaps occur when a number is divisible by multiple denominations. Use inclusion–exclusion with LCM to handle overlaps: add counts for single coins, subtract counts for pairs using their LCM, add for triples, and so on. Subsets can be enumerated efficiently using bit manipulation. LCM calculations rely on number theory concepts. Combine this counting function with binary search over the numeric range until the smallest value with at least k valid amounts is found.
The key insight: instead of generating the sequence, compute how many values fall below a threshold. Binary search converts the problem into repeated counting queries, which is dramatically faster when k can reach very large values.
Recommended for interviews: The heap method shows you recognize the problem as merging sorted sequences, which is a solid baseline. Interviewers typically expect the binary-search + inclusion–exclusion approach because it demonstrates stronger algorithmic thinking, familiarity with LCM/GCD math, and efficient counting techniques.
| Approach | Time | Space | When to Use |
|---|---|---|---|
| Min-Heap for Multiples | O(k log n) | O(n) | Useful when k is relatively small and you want a straightforward merge of multiple sorted sequences. |
| Binary Search + Inclusion-Exclusion Counting | O(2^n log R) | O(1) | Best for large k or large numeric ranges where generating values directly would be too slow. |