← All problems
Insert Delete GetRandom O(1)
Design a set supporting insert, delete, and getRandom (uniform over current elements), all in amortized O(1) time. The delete operation is the tricky one.
Complexity
Time O(1) avg, Space O(n)
Common pitfalls
- Linear delete scan
- Stale indices after swap
Your solution
Log in to save your code and track progress.