Design a basic bank system API
MetaSoftware Engineer · Online AssessmentLast updated
This question evaluates a candidate's ability to design and implement an in-memory banking API, focusing on data modeling, API semantics, invariants (such as monotonic timestamps and non-negative balances), idempotency, and basic concurrency control.
Design and implement an in-memory bank system. Provide an interface/class BankSystem with methods: bool createAccount(long timestamp, String customerId); int deposit(long timestamp, String customerId, int amount); int pay(long timestamp, String sourceAccountId, String targetAccountId, int amount). Define the data model, invariants (e.g., no negative balances), return semantics (e.g., new balance vs. error codes), and time/space complexity. Use hash maps (not lists) for constant-time account and transaction lookups. Address edge cases: duplicate or out-of-order timestamps, insufficient funds, unknown accounts, idempotency of retries, and basic concurrency assumptions.
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.