Problem Description
You are simulating the behavior of an ATM machine in Thailand. The ATM can dispense only three denominations of Thai Baht (THB): 100, 500, and 1000.
When a user enters a withdrawal amount, the ATM will always prioritize the largest denomination first, working downwards. Your task is to determine which banknotes are dispensed.
The ATM has the following rules:
It always dispenses the least number of banknotes possible, starting from the highest denomination.
The maximum withdrawal per transaction is 50,000 THB. If the user requests more than this amount, the system should return an error message.
If the amount is not exactly divisible by the available denominations (e.g., 125), the system should return an error stating the amount cannot be dispensed.
Function Signature
def withdraw(amount: int) -> Union[List[int], str]:
Input
-
amount
(int
): The amount of Thai Baht the user wants to withdraw.- Constraint:
1 ≤ amount ≤ 100000
- Constraint:
Output
A list of integers representing the denominations dispensed (e.g.,
[1000, 1000, 500]
)-
Or a string error message in the following cases:
- If the amount exceeds 50,000 THB.
- If the amount cannot be dispensed using only 100, 500, and 1000 THB notes.
Example 1
Input: 3500
Output: [1000, 1000, 1000, 500]
Example 2
Input: 370
Output: "Cannot dispense the requested amount with available denominations."
Example 3
Input: 60000
Output: "Withdrawal amount exceeds the maximum limit of 50,000 THB."
Additional Constraints
- The ATM only supports denominations: 100, 500, 1000 THB.
- All inputs are positive integers.
- Return the minimum number of notes required to fulfill the amount.
- Return appropriate error messages if the request is invalid.
- Try to solve the problem with
O(1)
Time and Space Complexity
💬 Your Turn!
Try solving the challenge and feel free to share your solution in the comments below. I'd love to see how you approach it — whether it's in Python, JavaScript, or any other language!
Top comments (0)