FastPrepTrending Stock

Trending Stock

Bloomberg LP logoBloomberg LP● HardNEW GRADONSITE INTERVIEW
Learn

Problem statement

Process commands:

  • process: record one occurrence of stocks[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^4 operations.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] runTrendingStock(String[] operations, String[] stocks) {
  // Write your code here.
}
operations["process","process","process","get","get","process","get"]
stocks["TSLA","AAPL","TSLA","","","NFLX",""]
expected["null", "null", "null", "TSLA", "AAPL", "null", "NFLX"]
Checking account…