Query an Account Balance as of Any Past Timestamp

Last updated: November 29, 2026

Quick Overview

Design a structure that records balance changes per account in timestamp order and answers the balance at any past time and the net change between two times.

Coinbase
Coding & Algorithms
Software Engineer
Coinbase
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Design a structure that records balance changes per account in timestamp order and answers the balance at any past time and the net change between two times.

Coinbase account statements, tax documents and support tooling all need point-in-time balances. The interviewer checks that you precompute running balances, pick the right bisect variant for ties and keep both writes and reads logarithmic or better.

What the Interviewer Expects
  • Store running balances, not raw deltas, to avoid summing per query
  • Use bisect_right so several changes at the same timestamp are all included
  • Define interval semantics for net change explicitly
  • Reject out-of-order writes or explain how to support them
  • Give O(1) append and O(log n) query
Key Topics to Cover
binary search
BST and ordered sets
prefix sums
time series
design a data structure
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 corrections inserted at past timestamps?
  • How would you store this for millions of accounts in a database?
  • How would you compute the total balance across all accounts at time t?
  • What changes if balances are kept per asset and you need USD value at t?
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

record(account, ts, delta) with non-decreasing timestamps per account. balance_at(account, ts) returns the balance after all changes at or before ts. net_change(account, t1, t2) returns the ch...

High-Level Design

Per account keep two parallel lists: timestamps and the balance after each change. Since writes arrive in order, appending keeps both sorted, and the running balance is just the previous balance plus ...


Submit Your Answer
Markdown supported