The Account Manager
A easy Python interview practice problem on DataDriven. Write and execute real python code with instant feedback.
- Domain
- Python
- Difficulty
- easy
- Seniority
- L4
Problem
You're replaying a checking account's transaction log. Implement a `BankAccount` class that opens at `initial_balance`, grows on a deposit, and shrinks on a withdrawal but refuses any withdrawal larger than the current balance. An `['undo']` reverses the most recent deposit or withdrawal that is still standing, so several undos in a row peel back that many transactions, while a balance read or an undo with nothing left to reverse changes nothing. Drive it from `bank_account_simulator(initial_balance, ops)`, which applies each op (`['deposit', amt]`, `['withdraw', amt]`, `['undo']`, or `['balance']`) in order and returns the closing balance, or the string `'ValueError'` the moment a withdrawal tries to pull more than the account holds.
Summary
Deposits, withdrawals, and a ledger you can walk back.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and checks it automatically.