Facebook | Phone | Randomized Set
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-05-08Added By Anonymous
Source: Link
Company: Meta
Role: e3, e4
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
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