Medium · Math
Random number not in array
Given maxVal in [0, 10⁹], an integer array blocked and a signed 64-bit 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. The same inputs always give the same result; return −1 if every value 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
Open every published interview problem, solution, scene, and memory room free, with no account.