HS08TEST - Editorial

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:

  1. The amount X should be a multiple of 5.
  2. 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 X is a multiple of 5: This can be verified using the modulo operation (X % 5 == 0).
  • Check if the account balance Y is sufficient: Ensure that Y is greater than or equal to X + 0.50 to 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.