Reported February 2026
Bloombergdesign

Insert, Delete, and Get Random in Constant Time

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 asked this one in February 2026, and the trap is in the delete. Everyone remembers the hash map plus array combo. Fewer people get the removal right when the element sits at the end of the array, or is the only one left. The task is a randomized set with insert, remove and getRandom, all average O(1). Here every getRandom hits a set of size 1, so the output is deterministic, but your structure still has to be honest. If the OA is in a day or two, learn the swap-with-last trick cold. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment.

The problem

Implement a set of integers that supports each of the following operations in average constant time:
insert x adds x when it is absent and otherwise leaves the set unchanged.
remove x deletes x when it is present and otherwise leaves the set unchanged.
getRandom returns one uniformly random value from the current set.
Process the commands in operations from left to right, starting from an empty set. Append one result for every command:
For insert x, append "true" if x was absent and became inserted, otherwise append "false".
For remove x, append "true" if x was present and became removed, otherwise append "false".
For getRandom, append the unique remaining value as a decimal integer string.
Every getRandom command is issued only when the set currently contains exactly one value, so the judged output is deterministic. Design the structure so that a later getRandom on a larger set would still be average O(1); the tests never ask for a stochastic sample from a multi-value set.
Each command is exactly insert x, remove x, or getRandom, where x is a signed decimal integer.
What the interview report shared
The Superday report asked to design a data structure that can put, delete, and get a random element, each in O(1).

Function
processRandomizedSet(operations: String[]) → String[]

Examples
Example 1
operations = ["insert 1","insert 2","remove 1","getRandom"]
return = ["true","true","true","2"]
Inserting 1 and 2 both succeed. Removing 1 leaves only 2, so getRandom must return 2.
Example 2
operations = ["insert 3","remove 4","insert 3","getRandom"]
return = ["true","false","false","3"]
The first insert creates singleton 3. Removing missing 4 and inserting 3 again both return false. The set still holds only 3.

Constraints
1 <= operations.length <= 10^5.
Each operation is exactly insert x, remove x, or getRandom.
-10^9 <= x <= 10^9.
Every getRandom occurs only when the set currently has size 1.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The pattern is a hash map from value to array index, plus a dynamic array of values. Insert checks the map, appends to the array, records the index. Remove looks up the index, copies the last array element into that slot, updates the map entry for that moved element, pops the array, then deletes the removed key from the map. The edge case that breaks the naive version: when the removed value is itself the last element. If you update the map for the moved element after deleting, or delete before updating, you can resurrect a stale key. Order matters. Do the overwrite and map update first, then pop and erase. Also parse the commands carefully, since x can be negative. Output strings must be exactly true, false, or the integer. If you freeze on the swap order during the live OA, StealthCoder can hand you the clean version.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Insert, Delete, and Get Random in Constant Time 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as insert delete getrandom o1. If you have time before the OA, drill that.

⏵ The honest play

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

Bloomberg reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Insert, Delete, and Get Random in Constant Time FAQ

What's the trick to this Bloomberg problem?+

Keep a dynamic array of values and a hash map from value to its array index. Removal swaps the target with the last array element, updates that element's index in the map, pops the array, and erases the key. Every step is O(1) average.

What edge case breaks most solutions?+

Removing the element that is already last in the array. If you swap and update the map in the wrong order, you leave a stale key or index behind. Overwrite first, update the map, then pop and erase the removed value.

How does getRandom work if the tests are deterministic?+

Every getRandom here runs on a set of size 1, so you return the only element. Still write it properly: pick a random index in the array and return that value. That keeps it O(1) on larger sets.

How do I parse the commands?+

Split each string on the space. The first token is the command, and the second, if present, is x. Parse x as an integer so negatives work. getRandom has no second token. Output true or false as lowercase strings, and the value as a decimal string.

How should I prep for this in 48 hours?+

Write the structure from scratch twice without looking. Test removing the last element, removing a missing value, inserting a duplicate, and removing down to one element. This design pattern shows up often, and it takes about 15 lines once you've got the swap order memorized.

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