Mutable Stock Price Top K

Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Bloomberg OA. Under 2s to a working solution.
Founder's read

Bloomberg reportedly put a mutable top-K stock tracker in front of candidates in May 2026, and the whole question hinges on one data structure choice. You get a stream of price updates and topK queries, and old prices have to disappear when a symbol is updated. If you've got an OA coming, this one rewards knowing how to handle stale entries in a heap or an ordered set. It's not hard once you see it. It's easy to blank on the update part under a timer. StealthCoder is the safety net that runs invisibly during the live OA if your mind goes empty.

The problem

Maintain the current integer price of each stock while processing a finite sequence of operations.
["update", symbol, price] creates the stock if necessary and replaces its current price.
["topK", k] returns up to k current stock symbols, ordered by descending price and then lexicographically by symbol when prices are equal.
If fewer than k stocks exist, return every current stock. Return one symbol list for each topK operation, in encounter order.

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 breaks the price tie between GOOG and MSFT lexicographically. After AAPL is updated to 400, it ranks first.
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 update or topK.
symbol contains between 1 and 10 uppercase English letters.
1 <= price <= 1000000000.
1 <= k <= 100000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that a plain heap can't delete an arbitrary entry, and updates replace prices. Keep a hash map from symbol to current price. For topK, you have two options. Option one: use a sorted structure keyed by (negative price, symbol), removing the old key on each update and inserting the new one. Option two: lazy deletion. Push (price, symbol) onto a heap on every update, and when you pop during topK, skip entries where the map price doesn't match, then push the valid ones back. The common pitfall is forgetting the tie-break, which is lexicographic ascending by symbol while price is descending. Another is treating an update as a new stock, so IBM shows up twice. With up to 100000 operations and k up to 100000, sorting the full set on every query can blow up, so avoid it. If you blank on the live OA, StealthCoder is the hedge that hands you the structure.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Mutable Stock Price Top K cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Bloomberg's OA.

Bloomberg reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Mutable Stock Price Top K FAQ

What's the trick to Bloomberg's Mutable Stock Price Top K?+

Track current prices in a hash map and handle stale entries. Either use an ordered set where you remove the old (price, symbol) pair before inserting the new one, or use a heap with lazy deletion that skips entries whose price doesn't match the map.

How hard is this problem really?+

Medium. The logic is simple, but the update semantics trip people up. You must replace a price, not add a second entry. The tie-break also flips direction: price descending, symbol ascending. Get those two right and the rest is bookkeeping.

Why not just sort all stocks on every topK query?+

With up to 100000 operations, re-sorting every stock per query can degrade to roughly n log n per call, which adds up fast. A maintained ordered structure or a heap with lazy deletion keeps each query closer to k log n.

How do I handle the tie-break correctly?+

Compare by price descending first, then symbol ascending. In a min-heap, store (-price, symbol) so the highest price comes out first and equal prices come out in alphabetical order. In Example 1, GOOG comes before MSFT at 310.

How do I prep for this in 48 hours?+

Write a heap with lazy deletion from scratch once, then an ordered-set version if your language supports one. Test with repeated updates to the same symbol and a k larger than the stock count. Those two cases catch most bugs.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Bloomberg.

OA at Bloomberg?
Invisible during screen share
Get it