Fewest Gift Card Denominations to Add So Every Amount Is Payable

Last updated: November 29, 2026

Quick Overview

You have a sorted list of gift card face values (each card usable at most once). Return the minimum number of new cards you must add so that every amount from 1 to n can be paid exactly with some subset of cards.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


You have a sorted list of gift card face values (each card usable at most once). Return the minimum number of new cards you must add so that every amount from 1 to n can be paid exactly with some subset of cards.

An Amazon onsite hard greedy question. It looks like a subset-sum DP, which is far too slow for n up to 2^31; the interviewer wants the reachable-prefix invariant and the argument that patching with the smallest unreachable amount is optimal.

What the Interviewer Expects
  • States the invariant: all amounts in [1, miss) are payable
  • Uses an existing card when its value is at most miss
  • Adds a card of value miss otherwise, doubling the range
  • Proves the greedy patch is optimal
  • Runs in O(len(cards) + log n)
Key Topics to Cover
greedy
invariants
subset sums
math
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the denominations to add.
  • Cards can be used unlimited times: how does the answer change?
  • What if added cards must come from a fixed allowed set?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: sorted list of positive integers cards and integer n >= 1 (up to 2^31 - 1). Output: min number of added positive integers so that every value in [1, n] is a subset sum....

High-Level Design

Maintain miss, the smallest amount we cannot yet pay; every amount below it is payable. Initially miss = 1. If the next card c satisfies c <= miss, adding it makes every amount below miss + c payabl...


Submit Your Answer
Markdown supported