Insert, delete, and get-random in O(1)
Asked at Citadel
Design a data structure (think: a live universe of tradable symbols you must sometimes sample uniformly at random) supporting:
insert(val), addval, returnTrueif it was not already present;remove(val), deleteval, returnTrueif it was present;get_random(), return a uniformly random current element.
All three must run in average time.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.