981. Time Based Key-Value Store - Day 6/31 Leetcode October Challenge

preview_player
Показать описание
Larry solves and analyzes this Leetcode problem as both an interviewer and an interviewee. This is a live recording of a real engineer solving a problem live - no cuts or edits!

#leetcode #coding #programming
Рекомендации по теме
Комментарии
Автор

I forgot to see constraint of timestamp is increasing and used sortedlist instead

narolavarshil
Автор

from sortedcontainers import SortedList
class TimeMap:

def __init__(self):


def set(self, key: str, value: str, timestamp: int) -> None:
self.lookup[key].add((timestamp, value))

def get(self, key: str, timestamp: int) -> str:
index=self.lookup[key].bisect_right((timestamp, "{"))
if index!=0:
return self.lookup[key][index-1][1]
return ""

narolavarshil