Time Based Key-Value Store
Updated
Problem statement
Build a time-based key-value store. For each key, it keeps every value stored under that key, together with the timestamp the value was stored at. The store starts empty.
You get four arrays of the same length: operations, keys, values and timestamps. Run the operations from left to right. At index i, operations[i] is one of these:
"set": storevalues[i]under the keykeys[i]at the timestamptimestamps[i]. Values stored earlier under the same key are kept."get": look at the values stored underkeys[i]at a timestamp less than or equal totimestamps[i]. Add the one with the largest such timestamp to the answer. If there is no such value, add the empty string"".
Return the answers of all "get" operations, in the order they ran.
Function
runTimeMap(operations: String[], keys: String[], values: String[], timestamps: int[]) → String[]Examples
Example 1
operations = ["set","get","get","set","get","get"]keys = ["home","home","home","home","home","home"]values = ["400k","","","425k","",""]timestamps = [2,1,2,5,4,9]return = ["","400k","400k","425k"]The key "home" gets "400k" at timestamp 2 and "425k" at timestamp 5. At timestamp 1 nothing is stored yet, so the first lookup returns "". At timestamps 2 and 4 the latest value is the one from timestamp 2, "400k". At timestamp 9 it is the one from timestamp 5, "425k".
Example 2
operations = ["set","set","set","get","get","get","get"]keys = ["door","roof","door","door","roof","door","roof"]values = ["red","blue","green","","","",""]timestamps = [1,3,6,5,5,6,2]return = ["red","blue","green",""]Each key has its own history. At timestamp 5, "door" still has "red", because "green" arrives at timestamp 6, and "roof" has "blue". At timestamp 6, "door" has "green". At timestamp 2, "roof" has nothing yet, so the last lookup returns "".
Example 3
operations = ["get","set","get","get"]keys = ["x1","x1","y2","x1"]values = ["","v1","",""]timestamps = [10,10,10,10000000]return = ["","","v1"]The first lookup runs before anything is stored, so it returns "". The key "y2" is never stored, so its lookup also returns "". The last lookup asks for "x1" at the largest timestamp and gets "v1", stored at timestamp 10.
Constraints
1 <= operations.length <= 10000keys.length == operations.lengthvalues.length == operations.lengthtimestamps.length == operations.length- Each
operations[i]is"set"or"get". 1 <= keys[i].length <= 10- When
operations[i]is"set",1 <= values[i].length <= 10. - When
operations[i]is"get",values[i]is""and is not used. keys[i]andvalues[i]contain only lowercase English letters and digits.1 <= timestamps[i] <= 10000000- The timestamps of the
"set"operations are strictly increasing, in the order the operations run.
More Zillow Phone Screen questions
- Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
- Filter Formatted Records by CriteriaPHONE SCREEN · Seen Sep 2023
- Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
- Jump GamePHONE SCREEN · Seen Dec 2022
- Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
- Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
- Two Sum: All PairsPHONE SCREEN · Seen Nov 2022
- Employee Free TimePHONE SCREEN · Seen Oct 2022
- First Unique Character in a StringPHONE SCREEN · Seen Oct 2022
- K-th Smallest Number in a StreamPHONE SCREEN · Seen Oct 2022
Similar questions at other companies
- Frequency-Weighted Next-Word SamplingGoogle · PHONE SCREENGoogle interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Consistent-Hash Packet RouterAmazon · PHONE SCREEN
- Snapshot Map with Sparse Version HistorySnorkel AI · PHONE SCREEN
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Design a Food Rating SystemApple · 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