2034. Stock Price Fluctuation Solution 1 from sortedcontainers import SortedList class StockPrice(object): def __init__(self): self.price = SortedList() self.time_price = {} self.max_time = 0 def update(self, timestamp, price): """ :type timestamp: int :type price: int :rtype: None """ if timestamp in self.time_price: self.price.remove(self.time_price[timestamp]) self.price.add(price) self.time_price[timestamp] = price self.max_time = max(self.max_time, timestamp) def current(self): """ :rtype: int """ return self.time_price[self.max_time] def maximum(self): """ :rtype: int """ return self.price[-1] def minimum(self): """ :rtype: int """ return self.price[0] # Your StockPrice object will be instantiated and called as such: # obj = StockPrice() # obj.update(timestamp,price) # param_2 = obj.current() # param_3 = obj.maximum() # param_4 = obj.minimum()