Spins Interview Question
Software EngineersCountry: United States
Interview Type: Phone Interview
My closest answer, in the 15 or so mins left, is follows:
1. Get a psuedo-random positive integer
2. Check if it's even. If so, replace in a stored array. Otherwise, skip.
Interviewer said this was better than my first approach of using the number-modulus-k to store into the array where the last int has 100% prob of being sampled. He said each number has 50% chance, which seemed uniformly random, but not ideal in all cases.
check out the reservoir sampling
- Anonymous July 16, 2015Cheers and Good luck