Kth Smallest Amount With Single Denomination Combination - Problem

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.

Input & Output

Example 1 — Basic Case
$ Input: coins = [3,5], k = 4
Output: 9
💡 Note: The amounts we can make are: 3, 5, 6, 9, 10, 12, 15, ... The 4th smallest is 9.
Example 2 — Single Coin
$ Input: coins = [5], k = 2
Output: 10
💡 Note: With only coin 5, we can make: 5, 10, 15, 20, ... The 2nd smallest is 10.
Example 3 — Common Multiples
$ Input: coins = [2,4], k = 3
Output: 6
💡 Note: Coin 2 makes: 2, 4, 6, 8, ... Coin 4 makes: 4, 8, 12, ... Combined unique amounts: 2, 4, 6, 8, ... The 3rd smallest is 6.

Constraints

  • 1 ≤ coins.length ≤ 15
  • 1 ≤ coins[i] ≤ 25
  • 1 ≤ k ≤ 2 × 109

Visualization

Tap to expand
Kth Smallest Amount - Single Denomination INPUT coins array: 3 5 coins = [3, 5] k = 4 Multiples of 3: 3, 6, 9, 12, 15... Multiples of 5: 5, 10, 15, 20... (No mixing allowed!) ALGORITHM STEPS 1 Generate Multiples List all possible amounts 2 Merge & Sort Combine into sorted order 3 Remove Duplicates Keep unique values only 4 Find Kth Element Return the 4th smallest Merged Sequence: 3 1st 5 2nd 6 3rd 9 4th 10 5th k=4 FINAL RESULT The 4th smallest amount: 9 9 = 3 × 3 (multiple of coin 3) Verification: 1st: 3 (3×1) 2nd: 5 (5×1) 3rd: 6 (3×2) 4th: 9 (3×3) OK Output: 9 Key Insight: Since coins cannot be combined, each valid amount is simply a multiple of ONE coin denomination. Binary search on answer: count how many multiples of each coin are less than or equal to mid value, using inclusion-exclusion to handle LCM overlaps. Time: O(2^n × log(max_answer)) TutorialsPoint - Kth Smallest Amount With Single Denomination Combination | Optimal Solution
Asked in
Google 12 Meta 8
3.2K Views
Medium Frequency
~35 min Avg. Time
89 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