class LotterySystem:
The round: four Bloomberg reports, November 2025 to February 2026: three from onsite or superday coding rounds, and one whose round is not named. One report names it as the classic Insert Delete GetRandom O(1) problem; another calls it a variant of it. One gives the full prompt as a lottery system. One graded part, then a follow-up that was discussed, not coded.
Problem (as reported)
Create a lottery storage system that lets you add participants, remove participants and pick a winner at random. Every operation must run in O(1).
Part 1 — add, remove and pick in O(1)
class LotterySystem:
def __init__(self): ...
def addParticipant(self, id: int) -> bool: ...
def removeParticipant(self, id: int) -> bool: ...
def randomPick(self) -> int: ...
addParticipant(id: int) adds a participant. Ids are unique. It returns True when the participant is added and False when they cannot be (here: the id is already in the system).removeParticipant(id: int) returns True when the participant is removed and False when they cannot be (the id is not in the system).randomPick() returns the id of a participant chosen at random, or -1 when there are no participants. The prompt says only "at random"; here every current participant must be equally likely (our reading, and the tests check it).list.remove is O(n) per removal. The editor cannot time your code, so the tests check the answers only; say what each call costs.randomPick does not remove the winner. The tests check this: two picks from a system with one participant both return that id.Follow-up (discussed, not graded): what if addParticipant can receive the same id more than once? One candidate was asked this and only talked it through. The solution's walkthrough covers one way to do it.
Notes: the class, the three methods, their return values, unique ids, -1 when empty and the O(1) rule are reported. One candidate first wrote a list, was told removal was O(n), and moved to an array plus a map of each id's index, swapping the removed id with the last one before popping. Ours: Python keeps the reported method names; picking does not remove the winner (the prompt's "no participants left" could mean winners leave, so ask); equal chances for every participant; the tests use Python's random module with a fixed seed and check the spread of many picks and of consecutive pairs of picks, so any uniform random choice passes and a fixed rotation does not.
Four reports: three from onsite or superday coding rounds, one with the round not named. One gives the prompt in full as a lottery system with the three methods and their return values. One names it as the classic Insert Delete GetRandom O(1) problem. One candidate, writing from memory, describes starting with a list, being told that removal is O(n), and moving to an array plus an index map with a swap-with-last delete. The fourth calls it a variant of the classic problem; that candidate was short on time, and was asked what happens when add receives duplicates. Three of the four candidates passed the rounds this was asked in; the fourth was rejected after a coding round and a design round on the same day. Reports from Bloomberg also say interviewers ask for a dry run, the time complexity and edge cases.
What the reports say: the prompt is a lottery system with add, remove and a random pick, all O(1). It is the classic Insert Delete GetRandom O(1) problem. One candidate started with a list, was told removal was O(n), and switched to an array plus an index map with a swap-with-last delete. One was asked how to handle duplicates in add and only talked it through. Bloomberg reports say interviewers want a dry run, the time complexity and edge cases.
Common mistakes (ours): Removing with list.remove; Not updating the moved element's index; Mishandling removal of the last element; Picking from a set or dict keys, which needs an O(n) copy to a list.
Edge cases to test (ours): Pick on an empty lottery; Remove the element stored last; Add an id twice; Remove an id twice; Remove everyone, then add again
Also reported as Insert Delete GetRandom O(1) · LeetCode 380 Variant
The round: four Bloomberg reports, November 2025 to February 2026: three from onsite or superday coding rounds, and one whose round is not named. One report names it as the classic Insert Delete GetRandom O(1) problem; another calls it a variant of it. One gives the full prompt as a lottery system. One graded part, then a follow-up that was discussed, not coded.
Problem (as reported)
Create a lottery storage system that lets you add participants, remove participants and pick a winner at random. Every operation must run in O(1).
Part 1 — add, remove and pick in O(1)
class LotterySystem:
def __init__(self): ...
def addParticipant(self, id: int) -> bool: ...
def removeParticipant(self, id: int) -> bool: ...
def randomPick(self) -> int: ...
addParticipant(id: int) adds a participant. Ids are unique. It returns True when the participant is added and False when they cannot be (here: the id is already in the system).removeParticipant(id: int) returns True when the participant is removed and False when they cannot be (the id is not in the system).randomPick() returns the id of a participant chosen at random, or -1 when there are no participants. The prompt says only "at random"; here every current participant must be equally likely (our reading, and the tests check it).list.remove is O(n) per removal. The editor cannot time your code, so the tests check the answers only; say what each call costs.randomPick does not remove the winner. The tests check this: two picks from a system with one participant both return that id.Follow-up (discussed, not graded): what if addParticipant can receive the same id more than once? One candidate was asked this and only talked it through. The solution's walkthrough covers one way to do it.
Notes: the class, the three methods, their return values, unique ids, -1 when empty and the O(1) rule are reported. One candidate first wrote a list, was told removal was O(n), and moved to an array plus a map of each id's index, swapping the removed id with the last one before popping. Ours: Python keeps the reported method names; picking does not remove the winner (the prompt's "no participants left" could mean winners leave, so ask); equal chances for every participant; the tests use Python's random module with a fixed seed and check the spread of many picks and of consecutive pairs of picks, so any uniform random choice passes and a fixed rotation does not.
What if addParticipant can receive the same id more than once? (when: after the O(1) version; discussed, not coded)
What the reports say: the prompt is a lottery system with add, remove and a random pick, all O(1). It is the classic Insert Delete GetRandom O(1) problem. One candidate started with a list, was told removal was O(n), and switched to an array plus an index map with a swap-with-last delete. One was asked how to handle duplicates in add and only talked it through. Bloomberg reports say interviewers want a dry run, the time complexity and edge cases.
Common mistakes (ours): Removing with list.remove; Not updating the moved element's index; Mishandling removal of the last element; Picking from a set or dict keys, which needs an O(n) copy to a list.
Edge cases to test (ours): Pick on an empty lottery; Remove the element stored last; Add an id twice; Remove an id twice; Remove everyone, then add again
If you have had this round, tell us how close this page was. It is how we keep the pages accurate.
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 65 Bloomberg questions, refreshed monthly from new candidate reports.