Google interview question - find top k trending elements in the last 10 minutes

Write a function to find out the top k trending stocks in the last 10 minutes.

The input is a continuous stream of strings representing the company of the stock that is sold.
eg. Amazon, Uber, Amazon, IBM etc...
You also need to write ingest API for this.

If the 10 min constraint is not present, then this boils down to top k frequent elements in an array for which the solutions are easily available. How to handle this time interval part ?

Note: Only one company's stock is sold in a particular minute.

Comments (5)