Implement a Simple Banking Ledger
CoinbaseSoftware Engineer · OnsiteLast updated
This question evaluates competence in designing an efficient, stateful ledger API and associated data structures, emphasizing correctness under invalid inputs, performance at scale, integer overflow handling, unit testing for edge cases, and transactional (atomic batch) behavior.
Design and implement a banking ledger for n accounts labeled 1..n with initial balances. Provide an API: deposit(id, amount) -> bool, withdraw(id, amount) -> bool, transfer(fromId, toId, amount) -> bool. Rules: return false for invalid account IDs or insufficient funds; otherwise apply updates and return true. Constraints: up to 200,000 operations, amounts up to 10^12, target O(
- per operation and O(n) space; assume single-threaded execution. Sub-questions: write unit tests for edge cases (invalid IDs, zero/negative amounts, overflow), extend to support atomic batches of operations with rollback on partial failure, and analyze time/space complexity and common pitfalls (e.g., integer overflow).
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.