Implement an ATM That Dispenses Large Notes First or Refuses

Last updated: November 29, 2026

Quick Overview

An ATM stores counts of 20, 50, 100, 200 and 500 notes. deposit(counts) adds notes; withdraw(amount) dispenses greedily from the largest note down, and if the greedy plan cannot hit the amount exactly the ATM refuses and dispenses nothing.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


An ATM stores counts of 20, 50, 100, 200 and 500 notes. deposit(counts) adds notes; withdraw(amount) dispenses greedily from the largest note down, and if the greedy plan cannot hit the amount exactly the ATM refuses and dispenses nothing.

A Google phone screen state-tracking question where the rule is fixed (greedy) even though greedy is not always optimal. The interviewer checks that you follow the stated policy precisely, roll back on failure, and avoid looping one note at a time.

What the Interviewer Expects
  • Use integer division to take many notes per denomination at once
  • Plan the withdrawal on a copy, commit only on success
  • Return -1 or an empty result on refusal without changing state
  • Note that greedy can refuse amounts that are actually payable
  • Keep each operation O(number of denominations)
Key Topics to Cover
simulation
greedy
state management
transactions
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
  • Give an example where greedy refuses but a different combination works.
  • How would you implement an exact-change withdrawal using DP when greedy fails?
  • How would you make withdrawals safe under concurrent access?
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

Denominations [20, 50, 100, 200, 500] stored as counts. deposit(list_of_5) adds counts. withdraw(amount) returns a list of 5 counts dispensed or [-1] if the greedy plan leaves a remainder. Gre...

High-Level Design

Keep counts. For a withdrawal, build a plan array without mutating state: for each denomination from largest, take = min(counts[i], rem // note), subtract. If rem is zero at the end, subtract ...


Submit Your Answer
Markdown supported