Problem · Hash Table
In-Memory Database Historical Lookup
Learn this problemProblem statement
Implement a field-based in-memory database that can answer historical lookback queries. Every operation argument is encoded as a string, and operation timestamps are strictly increasing.
Operations
["SET_AT", key, field, value, timestamp]: set or overwrite the field beginning attimestamp. The value does not expire. Return an empty string.["SET_AT_WITH_TTL", key, field, value, timestamp, ttl]: set or overwrite the field. It is visible during the half-open interval[timestamp, timestamp + ttl). Return an empty string.["DELETE_AT", key, field, timestamp]: delete the value visible attimestamp. Returntrueif a visible field was deleted, orfalseotherwise.["GET_WHEN", timestamp, key, field, at_timestamp]: return the value that was visible atat_timestamp. Returnnullif the record or field did not exist then. It is guaranteed thatat_timestamp <= timestamp.- When
at_timestampis0, return the value currently visible at the operation's owntimestamp.
Keep expired and deleted versions in history so earlier lookback queries remain answerable. A newer write replaces the older value from its own timestamp onward; an older value does not reappear when the newer value expires.
Function
inMemoryDatabaseHistoricalLookup(operations: String[][]) → String[]Examples
Example 1
operations = [["SET_AT","A","score","10","1"],["SET_AT_WITH_TTL","A","score","20","5","5"],["GET_WHEN","6","A","score","2"],["GET_WHEN","7","A","score","5"],["GET_WHEN","10","A","score","9"],["GET_WHEN","11","A","score","10"],["SET_AT","A","score","30","12"],["GET_WHEN","13","A","score","0"],["DELETE_AT","A","score","14"],["GET_WHEN","15","A","score","13"],["GET_WHEN","16","A","score","14"]]return = ["","","10","20","20","null","","30","true","30","null"]The value 20 is visible on [5,10), so the lookback at 9 finds it while the lookback at 10 returns null. Deleting at 14 does not erase the value 30 from earlier history.
More Anthropic problems
- Banking System, Part 1: Accounts and TransfersOA · Seen Jul 2026
- Banking System, Part 2: Top SpendersOA · Seen Jul 2026
- Banking System, Part 3: Scheduled PaymentsOA · Seen Jul 2026
- Banking System, Part 4: Merging and Balance HistoryOA · Seen Jul 2026
- Convert Stack Samples to Trace EventsPHONE SCREEN · Seen Jul 2026
- Cloud Storage SystemOA · Seen Jun 2026
- Repair the Bootloader ProgramONSITE INTERVIEW · Seen Jun 2026
- Normalize a DNS Domain NameOA · Seen May 2026