Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 1.32 KB

_981. Time Based Key-Value Store.md

File metadata and controls

51 lines (36 loc) · 1.32 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : October 24, 2024

Last updated : October 24, 2024


Related Topics : Hash Table, String, Binary Search, Design

Acceptance Rate : 49.36 %


Solutions

Python

class TimeMap:

    def __init__(self):
        self.vals = {}

    def set(self, key: str, value: str, timestamp: int) -> None:
        if key not in self.vals :
            self.vals[key] = [[], []]
        self.vals[key][0].append(value)
        self.vals[key][1].append(timestamp)

    def get(self, key: str, timestamp: int) -> str:
        if key not in self.vals :
            return ''
        if timestamp < self.vals[key][1][0] :
            return ''
        return self.vals[key][0][bisect_right(self.vals[key][1], timestamp) - 1]

# Your TimeMap object will be instantiated and called as such:
# obj = TimeMap()
# obj.set(key,value,timestamp)
# param_2 = obj.get(key,timestamp)