← Questions

Set with constant-time insert, delete and get random

0
GoogleCodingLast asked Jan 2026

Design a set with add, remove and get_random, all in average O(1); get_random returns each element with equal probability. Handle empty-set and missing-element cases. Follow-up: how would you make it safe for concurrent use (one lock for the set versus finer-grained locking)?

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding