#K90677. Stock Price Tracker
Stock Price Tracker
Stock Price Tracker
You are given a sequence of operations to manage a stock price tracker. The tracker supports the following operations:
- insert <stock> <price>: Insert a new stock or update the price of an existing stock.
- delete <stock>: Remove a stock from the tracker. If the stock does not exist, do nothing.
- min: Output the stock ticker with the minimum price.
- max: Output the stock ticker with the maximum price.
If a min or max command is issued when the tracker is empty, output EMPTY
.
The input is read from standard input (stdin) and the output is written to standard output (stdout).
inputFormat
The first line contains an integer Q, representing the number of operations. Each of the following Q lines contains one operation. The operations can be:
• insert <stock> <price>
— Insert or update the price for the given stock ticker.
• delete <stock>
— Delete the given stock from the tracker.
• min
— Output the stock ticker with the lowest price.
• max
— Output the stock ticker with the highest price.
It is guaranteed that all stock tickers are non-empty and do not contain spaces, and all prices are integers.
outputFormat
For each min
or max
operation, output the resulting stock ticker on a separate line. If the tracker is empty, output EMPTY
(without quotes).## sample
8
insert AAPL 150
insert GOOG 100
insert MSFT 200
min
max
delete GOOG
min
max
GOOG
MSFT
AAPL
MSFT
</p>