Saw this question on glassdoor for a unicorn, was wondering if anybody had any idea how to solve it:
New stock prices are coming every hour, Design a data structure to store stock prices and getMaxStock() to get Max stock at price at that instance for last K hours. K will be known since beginning. Stock prices may not come every hour.
For example, given K = 4, a data stream of values comes every hour --> Hour 1: [10,5,7], Hour 2: [7,8], Hour 3: [], Hour 4: [3,9], Hour 5: [4,6]...... At hour 1-4 getMaxStock() should return 10 and at hour 5 it should return 9.
The class has two methods: getMaxStock() and newStocks(data) where data is a list of new incoming stocks. So essentially each time newStocks is called, that means another hour has passed.