Facebook | Phone | Randomized Set
1719

https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/

Easy one but thought to put it here just to realize everybody sometimes you might be lucky on the interview ;)
Implement the collection that provides the following operations:

  • void AddElement(int elem)
  • void RemoveElement(int elem)
  • int GetRandomElement() - which returns a random element of collection with equal probability for each stored element

All above operations should work in O(1) time. Duplicated elements are allowed

Comments (2)