I got this question at a recent flipkart interview for SDE1.
Design a data structure to give top 10 stocks from a stream of tuple at any point of time.
tuple (id, stock-price)
Basically, getTop10() should be returning a list of top 10 stocks having maximum value at any point of time.
For example,
Stream -->>(a, 10), (b,20), (c,30) (d, 40) (a, 30) (d,10)
getTop2() returns [{a,30}, (c,30)];
I was not able to give a satisfactory solution. I tried using maxHeap but interviewer did not seem satisfied,