Streaming stock price - find min/max/current - with changes/deletion also streaming
Anonymous User
735

Here is a problem I am trying to find an optimal solution for

You are getting a stream of data in format {timestamp, price}. At any point of time you can be asked the min price, max price and most current price till now. Catch is that a single stream data can be a new reading or a mofication or a deletion.

In case of modification same timestamp will be sent which was sent earlier with modified price.
In case of deletion same timestamp will be sent which was sent earlier with a negative stock price.

Need an optimal solution.

Data example

{timestamp: 1, price: 20}
{timestamp: 2, price: 35}
{timestamp: 3, price: 34}
{timestamp: 4, price: 54}
{timestamp: 2, price: 45}
{timestamp: 1, price: -20}

Comments (1)