Simplified Time-Based Key-Value Store
Updated
Problem statement
Implement a simplified time-based key-value store by processing a sequence of operations in order.
Each operation is represented as an array of strings:
["set", key, value, timestamp]storesvalueforkeyattimestamp.["get", key, timestamp]asks for the value stored forkeyat the greatest set timestamp less than or equal totimestamp.
The timestamp in each operation is a base-10 integer encoded as a string. If a get operation has no qualifying stored value, its result is the empty string. Return the results of the get operations in their original order; set operations do not add an entry to the returned array.
Function
timeMapResults(operations: String[][]) → String[]Examples
Example 1
operations = [["set","foo","bar","1"],["get","foo","1"],["get","foo","3"],["set","foo","bar2","4"],["get","foo","4"],["get","foo","5"]]return = ["bar","bar","bar2","bar2"]The first two queries use the value stored at timestamp 1. After the second set, queries at timestamps 4 and 5 use bar2.
Example 2
operations = [["get","missing","7"],["set","x","one","10"],["get","x","9"],["get","x","10"]]return = ["","","one"]The missing key and the query before x is first stored both return an empty string. The exact-timestamp query returns one.
Example 3
operations = [["set","alpha","a1","2"],["set","beta","b1","3"],["set","alpha","a2","8"],["get","alpha","7"],["get","beta","100"],["get","alpha","8"]]return = ["a1","b1","a2"]Histories are independent by key, and each query uses the latest qualifying timestamp for that key.
Constraints
1 <= operations.length <= 200000- Every operation begins with
"set"or"get". - A set operation has exactly four fields; a get operation has exactly three fields.
1 <= key.length, value.length <= 100, and keys and values contain only lowercase English letters and digits.- Every timestamp is a base-10 integer in the range
[1, 10000000]. - The timestamps of set operations are strictly increasing.
More SpaceX interview questions
- Starlink Beam PlannerOA · PHONE SCREEN · Seen Nov 2026
- Timestamped Telemetry Stream DifferencesPHONE SCREEN · Seen Sep 2026
- Number of IslandsPHONE SCREEN · Seen Aug 2026
- Number of Islands IIPHONE SCREEN · Seen Aug 2026
- Button Combination DetectorPHONE SCREEN · Seen Feb 2026
- Pressure Chamber Linear InterpolationPHONE SCREEN · Seen Jun 2025
- Speed to Pressure LookupPHONE SCREEN · Seen Mar 2025
- Rocket Component CostONSITE INTERVIEW · Seen Aug 2025
- DNA Sequence MatchOA · Seen Apr 2025
- Find the Duplicate NumberONSITE INTERVIEW · Seen Jan 2021
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-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-Based Key-Value StoreVerkada · PHONE SCREENVerkada interview questions
- Interview Slot BookingTrueFoundry · PHONE SCREEN
- Frequency-Weighted Next-Word SamplingGoogle · PHONE SCREENGoogle interview questions
- Time-Based Key-Value Map With Floor and Ceiling QueriesCharacter.AI · PHONE SCREEN