Fewest Gift Card Denominations to Pay an Exact Play Store Balance
Last updated: November 29, 2026
Quick Overview
Google Play gift cards come in a fixed set of denominations with unlimited supply. Return the fewest cards that sum exactly to a balance of A, or -1 if it cannot be done.
0
0
0 solved
Google Play gift cards come in a fixed set of denominations with unlimited supply. Return the fewest cards that sum exactly to a balance of A, or -1 if it cannot be done.
Coin change is a staple of Google onsite coding rounds, and interviewers often frame it around Play credits. They are checking that you reject greedy with a counterexample, define the unbounded-knapsack state, and handle unreachable amounts cleanly.
What the Interviewer Expects
- Show greedy by largest denomination can fail
- Define fewest[a] for every amount up to A
- Use infinity for unreachable amounts and convert to -1 at the end
- Order loops correctly for unlimited supply
- Discuss BFS as an equivalent view
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return which cards to use, not just the count.
- Each denomination has a limited count. What changes?
- A is 10^9 but denominations are small. Any shortcut?
- Minimize the number of distinct denominations used instead.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list cards of positive integers (denominations) and integer A >= 0. Unlimited cards of each value. Output the minimum number of cards summing to exactly A, or -1. Greedy fails: with cards [...
High-Level Design
Let fewest[a] be the minimum cards to pay exactly a. The last card has some value c, leaving a - c: fewest[a] = 1 + min(fewest[a - c]) over c <= a. Base fewest[0] = 0, and unreachable amounts ...