← Questions
Bank ledger with two-step transfers and merges
0
I was asked this
No reports yet. Sign in to say where you were asked it.
Model simple bank accounts with deposits and withdrawals, a transfer flow that holds funds until the recipient accepts, and an account-merge step that must keep working even if a merged account is later recreated.
-
Level 1:
create_account(ts, id),deposit(ts, id, amount),withdraw(ts, id, amount); deposit and withdraw return the new balance orNone. -
Level 2:
transfer(ts, src, dst, amount)holds the money and returns"transfer1", ...;accept_transfer(ts, dst, transfer_id)must happen within 24 hours (86_400_000ms), or the money goes back. -
Level 3:
merge_accounts(ts, keep, gone): balances and pending transfers move tokeep;gonecan be created again later and must not receive the old account's transfers.
DAY_MS = 86_400_000
class Bank:
def create_account(self, ts, account_id): ...
def deposit(self, ts, account_id, amount): ...
def withdraw(self, ts, account_id, amount): ...
def transfer(self, ts, src_id, dst_id, amount): ...
def accept_transfer(self, ts, account_id, transfer_id): ...
def merge_accounts(self, ts, keep_id, gone_id): ...
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
