Implement a Simple Banking Ledger
Company: Coinbase
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Onsite
Quick Answer: 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.
Constraints
- Accounts are labeled 1..n
- Amounts must be positive
Examples
Input: ([100, 50], [('deposit', 1, 25), ('withdraw', 2, 70), ('transfer', 1, 2, 50)])
Expected Output: {'results': [True, False, True], 'balances': [75, 100]}
Explanation: Valid and invalid operations.
Input: ([0], [('withdraw', 1, 1), ('deposit', 2, 5), ('deposit', 1, 0)])
Expected Output: {'results': [False, False, False], 'balances': [0]}
Explanation: Invalid ids and nonpositive amounts.
Input: ([10, 0], [('transfer', 1, 1, 5)])
Expected Output: {'results': [True], 'balances': [10, 0]}
Explanation: Self-transfer is valid and leaves balance unchanged.
Hints
- Validate before mutating so failed operations leave balances unchanged.