AO
Back

Lottery System: Add, Remove and Pick a Random Participant in O(1)

Also reported as Insert Delete GetRandom O(1) · LeetCode 380 Variant

CodingOnsiteLast reported February 2026Medium Frequency

Problem Overview

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).
  • All three are O(1) on average. A plain list with 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.
  • Here 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.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 1
Trade-off discussion

What if addParticipant can receive the same id more than once? (when: after the O(1) version; discussed, not coded)

What Reports Emphasize

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

Practice

Write your own against 8 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Prepping for Bloomberg with friends?

Send them this page. It is free to read, no account needed.

More Bloomberg Questions

Free preview

Every question in the Bloomberg catalog gets this depth

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.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Bloomberg · Coding · Reported 4× across candidate reports
Is this helpful?