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
Coding & Algorithms
Software Engineer
Upstart
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
data structure design
binary search
versioning
ledgers
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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()...


Submit Your Answer
Markdown supported