I stumbled upon this interview question and I wanted to find a solution for it in JavaScript (rather than Java or C++):
Implement a set-like data structure that supports Insert, Remove, and GetRandomElement efficiently. Example: If you insert the elements 1, 3, 6, 8 and remove 6, the structure should contain [1, 3, 8]. Now, GetRandom should return one of 1, 3 or 8 with equal probability.
This is answered in Java here: Data structure: insert, remove, contains, get random element, all at O(1) However, it doesn't offer example code. I am a beginner and am just learning how to use hash tables so if you can give an explanation of the code, I would appreciate that!