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.
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
["ATM","deposit","withdraw","withdraw","withdraw"] [[],[[0,0,0,3,1]],[600],[500],[600]]
[null,null,[-1],[0,0,0,0,1],[0,0,0,3,0]]
The first 600 fails after tentatively choosing 500, without consuming it. After withdrawing 500 separately, three 200 notes can satisfy 600.
Constraints
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.