Medium · Math
Random number not in array
Given an integer maxVal, an integer array blocked and an integer seed, return an integer chosen uniformly at random from [0, maxVal] that is not in blocked (repeated values and values outside that range block nothing), using a random generator seeded with seed; return −1 if every value in [0, maxVal] is blocked.
Examples
Example 1
max=6, blocked=[1,3,5], seed=2Output: 4
Example 2
max=4, blocked=[0,2], seed=3Output: 3
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.