Design a Payment Ledger With Point-in-Time Balance Snapshots
Last updated: November 29, 2026
Quick Overview
Implement a ledger supporting `post(account, amount)`, `snapshot()` which returns a snapshot id, and `balance_at(account, snap_id)` which returns the account's balance as of that snapshot. Memory should grow with the number of posts, not the number of snapshots times accounts.
Upstart
November 29, 20260
0
0 solved
Implement a ledger supporting `post(account, amount)`, `snapshot()` which returns a snapshot id, and `balance_at(account, snap_id)` which returns the account's balance as of that snapshot. Memory should grow with the number of posts, not the number of snapshots times accounts.
Upstart services loans and reports balances to investors and credit bureaus as of specific cutoffs, so point-in-time accuracy is a real engineering concern. The onsite round checks that you avoid copying every balance on each snapshot and use per-account version history with binary search.
What the Interviewer Expects
- Store per-account histories of (snap_id, balance)
- Overwrite the latest entry if posting again within the same snapshot
- Answer historical queries with binary search
- Return 0 for accounts with no history at that point
- Analyze memory relative to posts
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support reversing a posted transaction after a snapshot was taken?
- How do you make this durable and safe under concurrent writers?
- How would you compute the total balance across all accounts at a snapshot efficiently?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Snapshots are numbered from 0. balance_at(a, s) reflects every post made before snapshot() returned s. Unknown accounts and accounts created after s report 0....
High-Level Design
For each account keep two parallel lists: snapshot ids at which its balance changed, and the balance after that change. The current snapshot id is the one that will be returned by the next `snapshot()...