Problem Link - ATM Practice Problem in 500 difficulty rating
Problem Statement:
Pooja wants to withdraw X US dollars from an ATM, and there are certain conditions to check before completing the transaction:
- The amount
Xshould be a multiple of 5. - Pooja’s account balance,
Y, should be sufficient to cover the withdrawal amount plus a bank charge of 0.50 US dollars.
Approach:
- Check if
Xis a multiple of 5: This can be verified using the modulo operation (X % 5 == 0). - Check if the account balance
Yis sufficient: Ensure thatYis greater than or equal toX + 0.50to cover the withdrawal and the bank charge. - If both conditions are met, the balance is updated by deducting
X + 0.50. - If either condition fails, the balance remains unchanged.
Complexity:
- Time Complexity:
O(1), as only basic arithmetic operations and condition checks are performed. - Space Complexity:
O(1), as only a few variables are used.