Time-Based Key-Value Store
Updated
Problem statement
Process timestamped set and get operations on a time-based key-value store.
- A
setstores the supplied value for its key and timestamp and returns"null". - A
getreturns the value for its key with the greatest stored timestamp that is at most the query timestamp. If no such value exists, return the empty string.
Process operations in their array order and return one result per operation.
Function
runTimeMap(operations: String[], keys: String[], values: String[], timestamps: int[]) → String[]Examples
Example 1
operations = ["set","get","get","set","get"]keys = ["foo","foo","foo","foo","foo"]values = ["bar","","","bar2",""]timestamps = [1,1,3,4,4]return = ["null","bar","bar","null","bar2"]Each query returns the latest value for foo whose stored timestamp does not exceed the query timestamp.
Example 2
operations = ["get","set","get"]keys = ["x","x","x"]values = ["","one",""]timestamps = [2,5,4]return = ["","null",""]Neither query has a stored version at or before its timestamp.
Constraints
1 <= operations.length <= 100000, and all four input arrays have the same length.- Each operation is exactly
"set"or"get". 1 <= key.length, value.length <= 100.1 <= timestamp <= 10^9.- For each key, timestamps supplied to
setare strictly increasing.
Source note: Author-written prompt excerpt retained for source fidelity.
Similar questions at other companies
- Consistent-Hash Packet RouterAmazon · PHONE SCREEN
- Snapshot Map with Sparse Version HistorySnorkel AI · PHONE SCREEN
- Time-Based Key-Value StoreOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- 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
- Versioned Key-Value Store with Suffix TruncationNuro · ONSITE INTERVIEWNuro interview questions
- Future-Effective Employee SalaryRippling · ONSITE INTERVIEWRippling interview questions
- Time-Based Key-Value StoreVerkada · PHONE SCREENVerkada interview questions