A feed sends (timestamp, price) records for one stock, out of order, and a later record for a timestamp you've already seen is a correction that replaces the earlier price.
Implement StockPrice:
update(timestamp, price): record (or correct) the price attimestamp.current(): the price at the latest timestamp seen so far.maximum(): the highest price among the current (corrected) records.minimum(): the lowest price among the current records.
current, maximum and minimum are only called after at least one update.
sp = StockPrice()
sp.update(3, 40)
sp.update(1, 70)
sp.current() # 40 (timestamp 3 is the latest)
sp.maximum() # 70
sp.update(1, 20) # correction: timestamp 1 is now 20, the 70 is gone
sp.maximum() # 40
sp.minimum() # 20
Constraints: timestamps and prices are positive integers up to 10**9; up to ~10^5 calls. Recomputing max over every record per query is too slow; aim for O(log n) per call.
Show hint
you don't have to delete an outdated price the moment it's corrected. It only matters once it would be the answer, and at that point you can check it against the current price for its timestamp.