← Questions
Set with constant-time insert, delete and get random
0
I was asked this
No reports yet. Sign in to say where you were asked it.
Design a set with add, remove and get_random, all in average O(1); get_random returns each element with equal probability. Handle empty-set and missing-element cases. Follow-up: how would you make it safe for concurrent use (one lock for the set versus finer-grained locking)?
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
