Design a mini banking system
Company: Meta
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Technical Screen
Design and implement an in-memory banking system with the following operations:
(
1) createAccount(accountId, initialBalance=
0);
(
2) deposit(accountId, amount);
(
3) transfer(fromId, toId, amount) that debits fromId and credits toId, rejecting the transfer if fromId has insufficient funds. Maintain, for each account, the cumulative outgoing transaction amount (sum of all debits initiated by that account). Then implement topNAccountsByOutgoing(n) that returns the top n accounts by total outgoing amount, breaking ties by accountId ascending. The output should be a list of strings formatted as "{outgoingAmount}:{accountId}". Describe your data structures, error handling (e.g., unknown account, invalid amounts, insufficient funds), and provide pseudocode for both a full-sort solution and a heap-based top-k solution. Analyze time and space complexity.
Quick Answer: This interview question evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer for Design a mini banking system states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.