Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Leetcode 380. Insert Delete GetRandom O(1)
Design a data structure supporting insert(val), remove(val), and getRandom() — which returns a uniformly random existing element — with each operation in average O(1) time. The key challenge is to combine O(1) existence checks/updates with O(1) random access so every current element has equal selection probability.
Asked at:
Meta
Amazon
Bloomberg
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Mid November, 2025
Bloomberg
Senior
mplement the RandomizedSet class: RandomizedSet() Initializes the RandomizedSet object. bool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, false otherwise. bool remove(int val) Removes an item val from the set if present. Returns true if the item was present, false otherwise. int getRandom() Returns a random element from the current set of elements (it's guaranteed that at least one element exists when this method is called). Each element must have the same probability of being returned.
Early October, 2025
Senior
Late July, 2025
Senior
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.