Skip to content

Practice Design an ATM Machine

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2241
LeetCode Problem

Design an ATM Machine

Problem Statement

ATM starts empty and stores notes in denominations [20,50,100,200,500]. deposit(banknotesCount) adds counts in that order. withdraw(amount) greedily takes the largest available denominations first and returns five dispensed counts. If that greedy attempt cannot make the exact amount, return [-1] and leave inventory unchanged; do not backtrack to smaller notes. Practice approach: Compute a tentative withdrawal from high denomination to low, taking min(available,remaining/denomination). Commit count changes only when the remainder becomes zero. Use wide integer counts. This task intentionally differs from searching for any possible coin combination.

Source: Design an ATM Machine on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
["ATM","deposit","withdraw","withdraw","withdraw"]
[[],[[0,0,0,3,1]],[600],[500],[600]]
Output
[null,null,[-1],[0,0,0,0,1],[0,0,0,3,0]]
Explanation

The first 600 fails after tentatively choosing 500, without consuming it. After withdrawing 500 separately, three 200 notes can satisfy 600.

Constraints

Each deposit has five counts between 0 and 10^9.
1 <= amount <= 10^9
At most 5000 deposit/withdraw calls, including at least one of each.
Total deposited count per denomination is at most 10^9.

Related LeetCode Problems

Practice more problems similar to Design an ATM Machine.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.