Time-Based Key-Value Store
Updated
Problem statement
Process an in-memory store whose values have timestamps. A set call records a value for a key; a get call asks for that key at a particular time.
For this exercise, assume calls arrive as a finite list of string arrays:
["set", key, value, timestamp]stores the value at that time.["get", key, timestamp]returns the value with the greatest stored timestamp less than or equal to the query time. Return an empty string if no such value exists.
Timestamps inside calls are decimal strings. Set timestamps are strictly increasing separately for each key; get times can be in any order. Return the get results in call order. A set call produces no output.
Function
timeStore(operations: String[][]) → String[]Examples
Example 1
operations = [["set","foo","bar","1"],["get","foo","0"],["get","foo","1"],["set","foo","new","4"],["get","foo","3"],["get","foo","4"]]return = ["","bar","bar","new"]The query at time 0 has no history. Time 1 returns bar; time 3 still returns bar; time 4 returns new.
Example 2
operations = [["get","missing","9"],["set","a","zero","0"],["set","b","other","0"],["get","b","0"],["get","a","100"]]return = ["","other","zero"]The missing key returns an empty string. Keys a and b keep separate histories, including time 0.
Constraints
- 1 <= operations.length <= 100000
- Each operation is ["set", key, value, timestamp] or ["get", key, timestamp].
- Keys and stored values have 1 to 20 lowercase English letters.
- Timestamps are decimal integers from 0 to 1000000000.
- Set timestamps for each key are strictly increasing.
More Citadel Onsite Interview questions
- Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Removal PoolONSITE INTERVIEW · Seen Sep 2026
- Centered K-by-K Submatrix SumsONSITE INTERVIEW · Seen Aug 2026
- Search Suggestions with a Prefix TreeONSITE INTERVIEW · Seen Aug 2026
- Traverse Interior Matrix Cells in Row-Major OrderONSITE INTERVIEW · Seen Aug 2026
- 2048 Simulation and Board CodecONSITE INTERVIEW · Seen Jan 2026
- Cancellable Priority Task QueueONSITE INTERVIEW · Seen Jan 2026
- Dynamic Weighted SamplingONSITE INTERVIEW · Seen Jan 2026
- Exchange Connection AlertsONSITE INTERVIEW · Seen Jan 2026
Similar questions at other companies
- Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
- Snapshot Map with Sparse Version HistorySnorkel AI · PHONE SCREEN
- Maintain a Consistent-Hashing RingCohesity · ONSITE INTERVIEW
- Maintain a Consistent-Hashing RingApple · PHONE SCREENApple interview questions
- Time-Based Key-Value StoreOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Time-Based Key-Value StoreCockroach Labs · PHONE SCREEN · ONSITE INTERVIEW
- Time Map with Sum and AverageConfluent · PHONE SCREENConfluent interview questions
- Structured Log Stream with QueriesOpenAI · PHONE SCREENOpenAI interview questions
- Time-Indexed Key-Value StoreTogether AI · ONSITE INTERVIEW
- Globally Versioned Key-Value StoreLyft · ONSITE INTERVIEWLyft interview questions