Mutable Stock Price Top K
Updated
Problem statement
Given operations, return one list of stock symbols for each topK query, in query order.
Maintain each stock's current integer price:
["update", symbol, price]creates the stock if needed and replaces its current price.["topK", k]returns up tokcurrent stock symbols, from highest price to lowest.
For equal prices, sort symbols in lexicographic order. Compare letters from left to right, putting the earlier letter first at the first difference. If one symbol is a prefix of another, put the shorter symbol first.
If fewer than k stocks exist, return all current stocks.
Function
trackTopStocks(operations: String[][]) → String[][]Examples
Example 1
operations = [["update","AAPL","150"],["update","MSFT","310"],["update","GOOG","310"],["topK","2"],["update","AAPL","400"],["topK","3"]]return = [["GOOG","MSFT"],["AAPL","GOOG","MSFT"]]The first query puts GOOG before MSFT because equal prices are resolved by lexicographic order. Updating AAPL to 400 gives it the highest price for the next query.
Example 2
operations = [["update","IBM","100"],["topK","3"],["update","IBM","90"],["topK","1"]]return = [["IBM"],["IBM"]]The first query returns every current stock because only one exists. Updating IBM replaces its old price rather than adding a second stock entry.
Constraints
1 <= operations.length <= 100000.- Every operation is either
updateortopK. symbolcontains between1and10uppercase English letters.1 <= price <= 1000000000.1 <= k <= 100000.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
- Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
- In-Memory Priority Task SchedulerRippling · PHONE SCREENRippling interview questions
- Balanced Session ManagerPalantir · PHONE SCREENPalantir interview questions
- Design a Food Rating SystemApple · PHONE SCREENApple interview questions
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN
- Lowest-Bid Auction SystemGoogle · ONSITE INTERVIEWGoogle interview questions
- Rank-Based Cache with a Data SourceLinkedIn · PHONE SCREENLinkedIn interview questions
- Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
- Notification Deduplication WindowGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions