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
Core interview problems are free with a full runner and lessons; Pro opens the complete library.