Design a data structure with push() and randompop(), which removes a uniformly random element. Then extend it to pop each element with probability proportional to its weight.
Unlock detailed company stats for this questionUpgrade
Community answers
No answers contributed by the community yet.
Related questions
Design a class that is built from an array of weights and returns a random index, choosing each index with probability proportional to its weight.For a portfolio of tickers, support add, remove and get-random in O(1). Then pick a ticker in proportion to its weight, and pick a uniformly random symbol from a stream of unknown length.Related courses

Course

Course