All problems
Time-Based Key-Value Store
Problem
Simulate a time-based key-value store.
operations contains "set" (keys[i], values[i] at timestamps[i]) or "get" (return the value for keys[i] at the largest timestamp less than or equal to timestamps[i]). Sets for the same key are performed with non-decreasing timestamps.
Return the list of recorded results (None for set, a string for get; "" when no value qualifies).
Hint
Appending (timestamp, value) pairs keeps each key's history sorted, and the last qualifying entry wins.
Test cases
case 1
in: [["set","set","get","get","get"],["foo","foo","foo","foo","foo"],["bar","bar2","","",""],[1,4,1,4,5]]
expected: [null,null,"bar","bar2","bar2"]
case 2
in: [["set","get"],["a","b"],[1,""],[10,5]]
expected: [null,""]
case 3
in: [["get"],["x"],[""],[0]]
expected: [""]
case 4
in: [["set","set","get","get"],["k","k","k","k"],[1,2,"",""],[5,5,5,6]]
expected: [null,null,2,2]
Starter codePython
def time_map_ops(operations, keys, values, timestamps):
# Your code here
pass4 test cases · run your code against them in the editor