0 day streak
Anonymous · shared experience20 Dec 2025 · 9 views

Bloomberg: Lottery pool with O(1) add, remove and uniform random pick

Interview question #Bloomberg DSA / coding

Problem. Design a LotterySystem class with these operations:

  • addParticipant(id): add a participant with a unique id. Return true on success, false if the add fails (for example, the id is already present).
  • removeParticipant(id): remove the participant. Return true on success, false if they were not there.
  • randomPick(): return the id of a uniformly random current participant, or -1 if the pool is empty.

Constraints. Every operation must run in O(1), and picks must be truly random over the current participants.

Discussion. This is the classic pairing of a hash map with a dynamic array. To remove a participant, swap them with the last array element and pop, updating the moved element's index in the map. The same onsite round also asked for the maximum nesting depth of brackets in a string.

What the interviewer cared about. The interviewers moved on as soon as a correct approach was clear. In a later round the candidate was told they were coding too fast. The candidate received an offer.

0 comments

Comments 0

No comments yet. Ask the author something, or add what happened in your own round.