Skip to content

Time-based Key Value Store ​

Time-based Key Value Store — LeetCode

Design a key-value store that stores multiple values per key at different timestamps and can retrieve the value at or before a given timestamp.

Approach ​

Make a dictionary<string, List<(int, string)> Set is straight forward. Just set the (timestamp, value) pair to the dictionary. For Get, start at 0 and length of list of values of the key. Then do a binary search on indexes. If something with less or equal timestamp is found, set it to result and move the left pointer. Else, move the right pointer.

Remarks ​

Array is always sorted because timestamp is increasing