Available question text
Design a data structure that supports three operations, all in average O(1) time:
- insert(val): adds val to the data structure if not already present
- remove(val): removes val if present
- getUnique(): returns a uniformly random element that has been inserted exactly once (i.e., never re-inserted after removal)
For example, after insert(1), insert(2), insert(1): getUnique() must return 2, since 1 was inserted more than once. After remove(1), both 1 and 2 are unique again, so getUnique() may return either.
Related questions
Continue with questions that share topics or the same question type.
- Design an indexed data structure with insert, replace, and search operations
Coding
- All O`one Data Structure
Coding · Design · Doubly-Linked List · Hash Table
- Classic data structure and algorithm coding problems .
Coding
- Data Structure with O(1) Set All Operation
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
Nebuis
Design a Data Structure with Insert, Remove, and GetRandom for Unique Elements in O(1)
Reported Aug 31, 2026 · 2 source reports
SENIOR
Source snapshot: Nov 12, 2026
View source