Trending Stock
Problem statement
Process commands:
process: record one occurrence ofstocks[i], return null.get: choose the stock with greatest current occurrence count, breaking ties by the most recent remaining occurrence; return it and remove that most recent occurrence.
Every get is valid. Return one string per operation.
Function
runTrendingStock(operations: String[], stocks: String[]) → String[]Examples
Example 1
operations = ["process","process","process","get","get","process","get"]stocks = ["TSLA","AAPL","TSLA","","","NFLX",""]return = ["null","null","null","TSLA","AAPL","null","NFLX"]TSLA first leads 2-1; after one removal the tie favors AAPL's later remaining occurrence, then NFLX is newest.
Constraints
- At most
10^4operations.