Make Change From a Cash Drawer With Limited Coins
Last updated: November 29, 2026
Quick Overview
A Square Register cash drawer holds a limited count of each denomination; return the combination that pays out a given change amount with the fewest bills and coins, or report that exact change is impossible.
Square
November 29, 20260
0
0 solved
A Square Register cash drawer holds a limited count of each denomination; return the combination that pays out a given change amount with the fewest bills and coins, or report that exact change is impossible.
Sellers taking cash on Square Point of Sale track drawer contents, and suggesting change is a small but real product feature. The interviewer wants to see you reject greedy when it fails, model the bounded supply correctly, and reconstruct the answer, not just the count.
What the Interviewer Expects
- Show a counterexample where greedy fails with limited counts
- Formulate as bounded knapsack over amounts
- Reconstruct which denominations are used
- Keep the DP within O(amount x denominations x log count)
- Return None cleanly when impossible
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
- How would you prefer keeping small coins in the drawer when two answers tie on count?
- Amounts can be up to 100000 cents; is the DP still fine on a tablet?
- How would you handle cash rounding rules like Canada's nickel rounding?
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: amount in cents and drawer mapping denomination to count. Output: a mapping of denomination to how many to hand out, minimizing total pieces, or None. Greedy fails: with one quarter and t...
High-Level Design
best[v] is the fewest pieces summing to v. Each denomination with count c is split into bundles of 1, 2, 4, ... plus a remainder, so any usage from 0 to c is a sum of distinct bundles. Each bundle i...