Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I that once in a technical interview and got the job (just paused for 30 seconds until the answer came to me). I think they expected a 15 minute process of problem solving.

If I recall correctly the question was something like:

You are sitting recording cars by their license plate as they drive down a road. You only have N spots on your worksheet. You can overwrite spots as many times as you need to. By the end of the day you must have an unbiased sampling of cars that have driven by you. How do you record the cars?



Nice statistical problem! I only thought of a solution that is valid for many cars and few worksheet spots. Were you able to fully solve it on the spot?


What other situations are you concerned with that your solution doesn’t handle?


The best solution I could think of on the spot was this: First write down every license place until it fills up. Then for each time a car drives by, give it a 1/2 chance to write it down. Moving down the list regardless of the outcome. Then once the bottom is reached, do it again but with 1/3 a chance. Over and over again, decreasing the chance each time.

I checked for which situations it is valid, and it surprisingly was when there are many more cars than the list size. But it is not valid when there are just a few more cars than the list size.


Mine was to roll a number between 1 and N once N is greater than M (N being cars seen so far, M your slots available). If you get a number that is less than or equal to M, replace that slot. If it is greater than M, that sample is dropped.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: