Search
⌘K

Leetcode 710. Random Pick with Blacklist

Given n and a blacklist of unique integers, design a data structure that returns a uniformly random integer from [0, n-1] excluding the blacklist while minimizing calls to the built-in random generator. Preprocess efficiently (using about O(blacklist.size) extra space) so picks can be done in O(1) time by compacting the valid values and remapping sampled indices.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.