A sensor feed reports prices tagged by timestamp, and may correct an earlier report. It processes q operations, each one of:
UPDATE t price — record that at timestamp t the price is price. If t was reported before, this correction overwrites the earlier value for that timestamp.CURRENT — report the price at the latest (largest) timestamp seen so far.MAX — report the maximum price among the current (corrected) records.MIN — report the minimum price among the current (corrected) records.It is guaranteed that at least one UPDATE occurs before any query.
Line 1: an integer q.
Next q lines: UPDATE t price, CURRENT, MAX, or MIN.
For each CURRENT, MAX, and MIN operation, in order, print the requested price.
Example 1
Input
6 UPDATE 1 10 UPDATE 2 5 CURRENT MAX MIN UPDATE 1 20
Expected
5 10 5
Explanation
Records are {t1:10, t2:5}. CURRENT is the price at the latest timestamp (t2), which is 5. MAX is 10 and MIN is 5.
Example 2
Input
6 UPDATE 5 30 UPDATE 3 40 CURRENT UPDATE 5 25 CURRENT MAX
Expected
30 25 40
Explanation
The latest timestamp is 5, so the first CURRENT is 30. After correcting t5 to 25, CURRENT is 25. MAX over {t5:25, t3:40} is 40.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →