Design a bank system with scheduled transfers
MetaSoftware Engineer · Online AssessmentLast updated
This question evaluates object-oriented design and stateful system skills, including time-ordered event processing, scheduling and cancellation semantics, balance accounting, and top-k aggregation using appropriate data structures.
Bank System (OOD): Accounts, Transfers, Scheduling, Top Spending, Merge
Design an in-memory banking system that supports:
- account creation
- deposits/withdrawals
- immediate transfers
- scheduled (delayed) transfers with cancellation
- querying top spenders
- merging accounts
Core rules
- Each account has a balance (integer, starts at 0).
- Each operation is called with a
timestamp. - Before executing any operation at time
t, the system must process all scheduled transfers whose execution time<= t. - “Spending” for a customer is the total money sent out (withdrawals + transfers out, including scheduled transfers once executed; depending on your interpretation, you may also count scheduled transfers as spending when reserved—state your choice and be consistent).
API
create_account(timestamp, customer_id) -> bool
- Create if not exists.
deposit(timestamp, customer_id, amount) -> bool
- Fail if account doesn’t exist.
withdraw(timestamp, customer_id, amount) -> bool
- Fail if account doesn’t exist or insufficient funds.
- Counts toward spending.
transfer(timestamp, from_id, to_id, amount) -> bool
- Immediate transfer.
- Fail if either account missing or insufficient funds.
- Counts
amounttowardfrom_idspending.
top_spending(timestamp, n) -> list<string>
- Return top
ncustomers formatted"customerId(total)". - Sort by total spending desc, then customerId asc.
schedule_transfer(timestamp, from_id, to_id, amount, delay) -> string | null
- Create a transfer that will execute at
timestamp + delay. - If invalid (missing accounts or insufficient funds), return
null. - Return a unique
transfer_idfor cancellation. - Funds may be “reserved” immediately or deducted at execution; choose one and document it.
cancel_transfer(timestamp, customer_id, transfer_id) -> bool
- Cancel only if:
transfer_idexists- status is still pending (not executed)
- the
customer_idis the sender - Return whether cancellation succeeded.
merge_account(timestamp, from_id, to_id) -> bool
- Merge
from_idintoto_id: - Move remaining balance into
to_id - Add spending totals
- Update any pending scheduled transfers that reference
from_idas sender or receiver to referenceto_id - Delete
from_id
Notes
- Assume up to ~1e5 operations.
- You may use a min-heap/priority queue for scheduled transfers.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.