Price tracker with late corrections
Write a class PriceTracker that records a stock's price over time, where some records arrive late or turn out to be wrong.
update(time, price)recordspriceattime. Times arrive in any order, and a time that was already recorded gets corrected: its new price replaces the old one.current()returns the price recorded at the latest time seen so far.highest()returns the highest price among all recorded times, counting only each time's newest price.lowest()returns the lowest such price.
Times and prices are positive integers, and the three queries are only called after at least one update. Every operation must take O(log n) amortized time, where n is the number of updates.
The tests call the provided run_tracker(ops): it applies each operation in order and returns the list of results (None for update, shown as null).
Besides the tests, one large input (7,000 prices, 9,800 queries) with a ~500 ms limit (scaled to your device's speed): brute force won't pass.
Examples
run_tracker([["update",1,10],["update",2,5],["current"],["highest"],["lowest"],["update",1,3],["current"],["highest"],["lowest"]])→[null,null,5,10,5,null,5,5,3]run_tracker([["update",5,40],["update",2,70],["current"],["highest"],["update",2,20],["highest"],["lowest"]])→[null,null,40,70,null,40,20]