Nerd Paradise : Coding Interview 3: A Test in Probability
Given a function called rand5() which returns a random number between 1 and 5 (inclusive), write a function called rand7() which returns a random number between 1 and 7.Be careful, the knee-jerk reaction is to call rand5() twice and add up the results to extend the range of rand5(). Do not go down this path since the probabilities are not even for a given output of rand5() + rand5(). The key here is to maintain fair probability at each step of the solution.
Imagine a 5x5 grid with numbered cells.
Read full article from Nerd Paradise : Coding Interview 3: A Test in Probability
No comments:
Post a Comment