Python 16 lines, 95.71% speed
We have to generate numbers in [0,N) excluding integers in set B. That means that are M = N-len(B) valid numbers. So, generate random index in [0,M); if that in
We have to generate numbers in [0,N) excluding integers in set B. That means that are M = N-len(B) valid numbers. So, generate random index in [0,M); if that index is not excluded, return it. Otherwise, map it to a non-excluded value in [M,N).\n\n```\nclass Solution:\n\n    def __init__(self, N: int, B: List[int]):\n        B = frozenset(B)\n        self.M = M = N-len(B)\n        self.D = D = dict()\n        for b in B:\n            if b < M:\n                while M in B:\n                    M += 1\n                D[b] = M\n                M += 1\n\n    def pick(self) -> int:\n        i = randrange(self.M)\n        return self.D.get(i,i)\n```
[]