I was given this problem in an interview. How would you have answered?
Design a data structure that offers the following operations in O(1) time:
Cant we do this using HashSet of Java? It provides insert, del, search all in O(1) by default. For getRandom we can make use of iterator of Set which anyways gives random behavior. We can just iterate first element from set without worrying about rest of the elements
public void getRandom(){
Iterator sitr = s.iterator();
Integer x = sitr.next();
return x;
}