insert(val)
, check if val
is already in the HashMap. If it is, return false
. Otherwise, add val
to the ArrayList and put val
and its index into the HashMap, then return true
.remove(val)
, check if val
is in the HashMap. If it isn't, return false
. Otherwise, get the index of val
, swap the last element in the ArrayList with val
, update the index of the swapped element in the HashMap, remove the last element from the ArrayList, remove val
from the HashMap, and return true
.getRandom()
, generate a random index and return the element at that index in the ArrayList.