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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

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
Greedy
Simulation
Counting
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
  • 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 Problems
Sample 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 5and5 and 10 bills are in the till. A 5needsnochange.A5 needs no change. A 10 needs one 5.A5. A 20 needs 15:givea15: give a 10 and a 5ifpossible,elsethree5 if possible, else three 5 bills.

The greedy choice is to spend the $10...


Submit Your Answer
Markdown supported