Insert delete getrandom O(1)

0
Remix

Design a set with insert, remove and getRandom (each element equally likely), all in average constant time, using an array of values and a map from value to index; remove by swapping with the last element.

MetaTechnical phone screenLast asked Jul 2025
No answer yet. Write the first one; the best answer gets endorsed.