← Questions

Insert delete getrandom O(1)

0
MetaCodingLast asked Jul 2025

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.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding