Time Based Key-Value Store

Medium

Topics
Hash TableBinary SearchDesign

Design TimeMap with set(key, value, timestamp) and get(key, timestamp). get returns the value set for key with the largest timestamp <= timestamp, or an empty string if none.

Example 1

Input:  operations = ["TimeMap","set","get","get","set","get","get"], values = [[],["foo","bar",1],["foo",1],["foo",3],["foo","bar2",4],["foo",4],["foo",5]]
Output: [null,null,bar,bar,null,bar2,bar2]

Constraints

  • 1 <= key.length, value.length <= 100
  • set timestamps are strictly increasing per problem.
  • At most 2*10^5 calls.
Run ⌘' · Submit ⌘⏎