Preparing your design workspace

Loading the problem and your saved attempt…

Design an O(1) Randomized Set

Design an in-memory set that supports membership updates and uniform random selection in average constant time.

For this exercise, assume you are designing an in-memory Randomized Set component inside one process. It must insert a value only when absent, remove a value only when present, and return a uniformly random current member.

Insert and remove report whether membership changed, random selection is called only when the set is nonempty, and each operation should run in average O(1) time. The component receives its source of randomness as a dependency so behavior can be tested; persistence and distributed coordination are out of scope.

Produce a cohesive object-oriented design, its public contracts, and an interaction walkthrough without writing production code.