Calculate number of notes from an ATM machine
Filed under Deutsche Bank
Free read 1 of 3Confirm if the goal is the minimum number of notes or any combination.
The question
Given an amount in rupees, calculate the minimum number of 500 and 100 rupee notes required to make that amount. Assume the amount is always a multiple of 100.
Constraints
- Amount must be a multiple of 100
- Amount > 0
- Only 500 and 100 rupee notes are available
Examples
- Input
- 1200
- Output
- 2 notes of 500, 2 notes of 100
- Why
- 1200 = 2 * 500 + 2 * 100
Approach
Confirm if the goal is the minimum number of notes or any combination.
Divide the amount by 500 to get the count of 500 notes. Use the modulo operator to find the remaining amount, then divide by 100 to get the count of 100 notes.
Handle cases where the amount is less than 500.
Solution
O(1) time, O(1) space
def count_notes(amount):
n500 = amount // 500
n100 = (amount % 500) // 100
return n500, n100
assert count_notes(1200) == (2, 2)
assert count_notes(400) == (0, 4)
assert count_notes(500) == (1, 0)
Tips
- What they are testing: Test with amounts less than 500 and amounts that are multiples of 500.
- Common mistake: Forgetting to handle the remainder after taking the maximum number of 500 notes.
Related Deutsche Bank questions
Collected from public candidate posts and coding forums. Updated Nov 2026.