← Questions

Bank ledger with two-step transfers and merges

0
AnthropicCodingLast asked Jun 2026

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 or None.
  • 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_000 ms), or the money goes back.
  • Level 3: merge_accounts(ts, keep, gone): balances and pending transfers move to keep; gone can 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): ...
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