This question evaluates a candidate's competency in designing and analyzing randomized data structures that support O(1) average-time add, remove, and multiplicity-weighted getRandom operations, emphasizing hashing, index management, and probabilistic reasoning about sampling by multiplicity.

Write code for a data structure that supports add(x), remove(x), and getRandom() in average O(