1] that is You are given an integer n and an array of unique integers blacklist. Design an algorithm to pick a random integer in the range [0, n- not in blacklist. Any integer that is in the mentioned range and not in blacklist should be equally likely to be returned. Optimize your algorithm such that it minimizes the number of calls to the built-in random function of your language.
1] that is You are given an integer n and an array of unique integers blacklist. Design an algorithm to pick a random integer in the range [0, n- not in blacklist. Any integer that is in the mentioned range and not in blacklist should be equally likely to be returned. Optimize your algorithm such that it minimizes the number of calls to the built-in random function of your language.
Related questions
Question
![You are given an integer n and an array of unique integers blacklist.
Design an algorithm to pick a random integer in the range [0, n − 1] that is
not in blacklist. Any integer that is in the mentioned range and not in
blacklist should be equally likely to be returned.
Optimize your algorithm such that it minimizes the number of calls to the
built-in random function of your language.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F32804661-af85-4575-948f-43416d3226b1%2Fc8be694a-78ac-4ba6-b820-0415762c0a36%2Fe2ssgpk_processed.png&w=3840&q=75)
Transcribed Image Text:You are given an integer n and an array of unique integers blacklist.
Design an algorithm to pick a random integer in the range [0, n − 1] that is
not in blacklist. Any integer that is in the mentioned range and not in
blacklist should be equally likely to be returned.
Optimize your algorithm such that it minimizes the number of calls to the
built-in random function of your language.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 5 images
