Bitemporal Position Store With As-Of and Correction Queries
Last updated: November 29, 2026
Quick Overview
Implement a store of positions keyed by book and symbol where each record has a valid-from time and a knowledge (recorded) time, and answer queries of the form: what was the position effective at valid time V, as the firm knew it at knowledge time K.
Balyasny
November 29, 20260
0
0 solved
Implement a store of positions keyed by book and symbol where each record has a valid-from time and a knowledge (recorded) time, and answer queries of the form: what was the position effective at valid time V, as the firm knew it at knowledge time K.
Risk and compliance teams at a multi-manager fund must reproduce exactly what a risk report showed on a past date, even after trade breaks and back-dated corrections are booked. This onsite problem tests whether a candidate can reason about two time axes and pick an indexing scheme that keeps queries fast.
What the Interviewer Expects
- Explain the difference between valid time and knowledge time with a concrete correction example
- Define the precedence rule: latest valid_from not after V, then latest knowledge time not after K
- Use sorted storage and binary search instead of scanning all history
- Handle corrections that set a position to zero
- Discuss worst-case cost and how a production table would index this
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 return the full position history for a range of valid times as known at K?
- How would you model this in a SQL table and which index would you add?
- How would a risk report snapshot reference this store so it is reproducible?
- What happens if two records share both valid_from and knowledge time?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
record(book, sym, valid_from, kt, qty) appends; history is never overwritten. as_of(book, sym, V, K) considers only records with valid_from <= V and kt <= K. Among those, the one with the late...
High-Level Design
Group records per (book, symbol) in a list sorted by (valid_from, kt). Binary search for the last row with valid_from <= V, then walk backward. The first row we meet that is known by K fixes the w...