Correctable Stock Price Tracker
Problem statement
Process a parsed stock-price feed. Each operation is either SET timestamp price, which inserts or corrects that timestamp's price, or DELETE timestamp, which removes the timestamp if present.
After every operation, return [latestPrice, minimumPrice, maximumPrice]. The latest price belongs to the greatest stored timestamp. When no prices remain, return [-1,-1,-1].
Timestamps and prices are integers. Operations appear in feed order, which need not match timestamp order.
Function
trackStockPrices(operations: String[]) → int[][]Examples
Example 1
operations = ["SET 1 10","SET 2 5","SET 1 3","DELETE 2"]return = [[10,10,10],[5,5,10],[5,3,5],[3,3,3]]The third operation corrects timestamp 1; deleting timestamp 2 makes timestamp 1 latest again.
Example 2
operations = ["SET 5 7","DELETE 5"]return = [[7,7,7],[-1,-1,-1]]Deleting the sole price empties the tracker.
Example 3
operations = ["DELETE 9","SET 3 4"]return = [[-1,-1,-1],[4,4,4]]Deleting an absent timestamp is a no-op.
Constraints
0 <= operations.length <= 2000.1 <= timestamp, price <= 10^9.- Every operation is exactly
SET t porDELETE t.