Stock Price Fluctuation
Medium · Heap & Priority Queue · about 25 minutes
Asked at Google, Amazon, Atlassian, Microsoft, Asana, Notion, GitLab, Airtable, Glean.
A stream delivers (timestamp, price) records, possibly out of order; a later record for the same timestamp corrects the earlier price.
StockPrice()creates the tracker.update(timestamp, price)records or corrects the price attimestamp.current()returns the price at the latest timestamp.maximum()/minimum()return the highest / lowest current price over all timestamps.