bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 981. Time Based Key-Value Store

981. Time Based Key-Value Store

Leetcode Solutions

Array + Binary Search

  1. Initialize a hashmap keyTimeMap to store key-value pairs, where the value is an array of (timestamp, value) pairs.
  2. Implement the set method to append a new (timestamp, value) pair to the array associated with the given key in keyTimeMap.
  3. Implement the get method to perform a binary search on the array associated with the given key to find the largest timestamp that is less than or equal to the requested timestamp.
  4. If a suitable timestamp is found, return the corresponding value; otherwise, return an empty string.
UML Thumbnail

Hashmap + Linear Search

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...