Design a mini banking system
MetaSoftware Engineer · Technical ScreenLast updated
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.
Design and implement an in-memory banking system with the following operations: (
- createAccount(accountId, initialBalance= 0); (
- deposit(accountId, amount); (
- 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.
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.