5
self.highestTimestamp = 09
def update(self, timestamp: int, price: int) -> None:10
# Keep track of current prices11
self.timestamps[timestamp] = price12
self.highestTimestamp = max(self.highestTimestamp, timestamp)15
heappush(self.minHeap, (price, timestamp))16
heappush(self.maxHeap, (-price, timestamp))18
def current(self) -> int:19
# Just return the highest timestamp in O(1)20
return self.timestamps[self.highestTimestamp]22
def maximum(self) -> int:23
currPrice, timestamp = heappop(self.maxHeap)25
# If the price from the heap doesn't match the price the timestamp indicates, keep popping from the heap26
while -currPrice != self.timestamps[timestamp]:27
currPrice, timestamp = heappop(self.maxHeap)29
heappush(self.maxHeap, (currPrice, timestamp))32
def minimum(self) -> int:33
currPrice, timestamp = heappop(self.minHeap)35
# If the price from the heap doesn't match the price the timestamp indicates, keep popping from the heap36
while currPrice != self.timestamps[timestamp]:37
currPrice, timestamp = heappop(self.minHeap)39
heappush(self.minHeap, (currPrice, timestamp))