Probability function
This is apparently another Google interview question ..
Write a function that take a number between 1 and n as input such that it returns true 1/n times and every other time it returns a false.
My solution, the function generates a random number between 1 and n, including 1&n. The function will return 1 every time the generated number is 1, every other time it returns a 0.
No comments:
Post a Comment