Practice Time Based Key-Value Store
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
TimeMap stores versions through set(key,value,timestamp). get(key,timestamp) returns the value stored at the greatest timestamp no later than the query, or an empty string if none qualifies. Timestamps in set calls are strictly increasing. Practice approach: Append (time,value) pairs to a list for each key. Binary-search that key's list for the rightmost timestamp at most the query. Appending is amortized O(1), and a query is O(log m) for m versions of that key. Test queries before the first version, exactly at a stored time, and between versions.
Source: Time Based Key-Value Store on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["TimeMap","set","set","get","get","get","get"] [[],["mode","a",2],["mode","b",5],["mode",1],["mode",4],["mode",5],["other",8]]
[null,null,null,"","a","b",""]
The query at 4 uses the version at 2; queries before any version or for absent keys return an empty string.
Constraints
Related LeetCode Problems
Practice more problems similar to Time Based Key-Value Store.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.