Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

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 ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access