Give Exact Change at a Google Store Pop-Up With Only Small Bills
Last updated: November 29, 2026
Quick Overview
A Google Store pop-up sells a $5 sticker and starts with no cash. Customers pay in order with a $5, $10, or $20 bill; return whether the cashier can give every customer correct change.
0
0
0 solved
A Google Store pop-up sells a $5 sticker and starts with no cash. Customers pay in order with a $5, $10, or $20 bill; return whether the cashier can give every customer correct change.
Easy greedy questions like this appear in Google online assessments to check basic simulation and one greedy choice. The interviewer looks for why you should hand out a $10 before two $5 bills when making $15 change.
What the Interviewer Expects
- Simulate the till with counts of $5 and $10 bills
- Prefer giving a $10 plus a $5 for $15 change
- Explain why $20 bills never need to be tracked
- Return early on the first failure
- O(n) time, O(1) space
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
- Generalize to arbitrary denominations; does greedy still work?
- Return the index of the first customer who cannot be served.
- Allow the cashier to reorder the queue: when can everyone be served?
- Price and bills are inputs; prove or refute greedy for that case.
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 of bills, each 5, 10, or 20, in arrival order. Each customer buys one $5 item. Output: True if change can be made for everyone....
High-Level Design
Track how many 10 bills are in the till. A 10 needs one 20 needs 10 and a 5 bills.
The greedy choice is to spend the $10...