Kth Smallest Amount With Single Denomination Combination - Problem
The Coin Collection Challenge

Imagine you're a coin collector with infinite coins of different denominations. You can create amounts by using coins, but here's the twist: you can only use coins of the same denomination at a time.

Given an array coins representing different coin denominations and an integer k, find the k-th smallest amount that can be made using coins of any single denomination.

For example, with coins [3, 6, 9], you can make:
• Using denomination 3: amounts 3, 6, 9, 12, 15, 18, 21, ...
• Using denomination 6: amounts 6, 12, 18, 24, 30, ...
• Using denomination 9: amounts 9, 18, 27, 36, ...

The sorted sequence of all possible amounts is: [3, 6, 9, 12, 15, 18, ...]

Input & Output

example_1.py — Basic Case
$ Input: coins = [3, 6, 9], k = 5
Output: 15
💡 Note: Possible amounts: 3×1=3, 3×2=6, 6×1=6, 3×3=9, 9×1=9, 3×4=12, 6×2=12, 3×5=15... Unique sorted: [3,6,9,12,15,...]. The 5th smallest is 15.
example_2.py — Small Values
$ Input: coins = [2, 4], k = 3
Output: 6
💡 Note: Amounts from coin 2: 2,4,6,8,10... Amounts from coin 4: 4,8,12... Combined unique sorted: [2,4,6,8,10,12...]. The 3rd smallest is 6.
example_3.py — Single Coin
$ Input: coins = [5], k = 4
Output: 20
💡 Note: Only one denomination 5, so amounts are 5,10,15,20,25... The 4th smallest is 20.

Visualization

Tap to expand
The Multiplication RaceTrack 3:3691215Track 6:61218Track 9:918Binary Search:Searching position 15Position 15Count at position 15:Track 3: floor(15/3) = 5 hitsTrack 6: floor(15/6) = 2 hitsTrack 9: floor(15/9) = 1 hitTotal unique hits = 6 ≥ 5, so k=5 is ≤ position 15!
Understanding the Visualization
1
Set Up Race Tracks
Each coin creates its multiplication sequence (3→6→9..., 6→12→18...)
2
Binary Search Position
Guess a position and count how many hits occur at or before it
3
Count with Inclusion-Exclusion
Use floor(position/coin) for each track, subtract overlaps
4
Adjust Search Range
If count≥k search left, if count<k search right until exact position
Key Takeaway
🎯 Key Insight: Rather than generating all amounts, we binary search on the position and count how many 'hits' occur at or before each guessed position using simple division!

Time & Space Complexity

Time Complexity
⏱️
O(U × n + U log U)

U is upper bound, n is number of coins. Generate U×n multiples, then sort U unique values

n
2n
Linearithmic
Space Complexity
O(U)

Store all unique amounts up to upper bound U

n
2n
Linear Space

Constraints

  • 1 ≤ coins.length ≤ 20
  • 1 ≤ coins[i] ≤ 104
  • 1 ≤ k ≤ 2 × 109
  • All coin values are positive integers
  • You have infinite coins of each denomination
Asked in
Google 35 Amazon 28 Meta 22 Microsoft 15
28.5K Views
Medium Frequency
~35 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen