# Leetcode 2034 - Stock Price Fluctuation

Note:

• To quickly get max and min from a series of data, we should consider priority queue.
• And because some data would be updated, so we need a hash table to maintain the correct price.
• So when we get {timestamp, price} form pq, if the price is not correct, it means the obj is stale and we should pop it and move to the next top of the pq.

Question:

You are given a stream of records about a particular stock. Each record contains a timestamp and the corresponding price of the stock at that timestamp.

Unfortunately due to the volatile nature of the stock market, the records do not come in order. Even worse, some records may be incorrect. Another record with the same timestamp may appear later in the stream correcting the price of the previous wrong record.

Design an algorithm that:

• Updates the price of the stock at a particular timestamp, correcting the price from any previous records at the timestamp.
• Finds the latest price of the stock based on the current records. The latest price is the price at the latest timestamp recorded.
• Finds the maximum price the stock has been based on the current records.
• Finds the minimum price the stock has been based on the current records.

Implement the StockPrice class:

• StockPrice() Initializes the object with no price records.
• void update(int timestamp, int price) Updates the price of the stock at the given timestamp.
• int current() Returns the latest price of the stock.
• int maximum() Returns the maximum price of the stock.
• int minimum() Returns the minimum price of the stock.

Example:

Code: