Live data from Hacker News

My Job Interview at Google

catonmat.net

51–60 of 114 posts

Re: My Job Interview at Google

#52
post #46

He seems pretty excited for not getting the job.

SREs are on call. That means they carry a pager/cell phone and must be accessible at all times. He should be happy he didn't get picked ;).

> must be accessible at all times

Nope, just when they're on call. I was snowboarding in Montana for a week last winter with my google SRE buddy, so I'm pretty sure about this :)

Re: My Job Interview at Google

#53

Could anyone point me on how to solve this(either a solution or preferrably a pointer on how to get to it): "Q: Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7." First I thought it was simple but the I got stuck, maybe I'm just tired. No matter how I twsit and turn it I seem to get only an even distribution over 5 numbers.

My team uses this as a screening question, so I won't give you the answer - but you forgot to mention that both the rand5 and rand7 should have a uniform distribution. :)

I'll give you a hint, though - the solution is not elegant at all. Which is part of the point.

Re: My Job Interview at Google

#54
post #40

Could anyone point me on how to solve this(either a solution or preferrably a pointer on how to get to it): "Q: Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7." First I thought it was simple but the I got stuck, maybe I'm just tired. No matter how I twsit and turn it I seem to get only an even distribution over 5 numbers.

Execute f 7 times, add all numbers, call that x. Then you do mod(x,7)+1, and you get a random number between 1 and 7. If the original function was unbiased, this one is going to be unbiased too.

This won't work. f gives 1 to 5. 7 * f gives 7 to 35. But 7 to 35 will not be evenly generated. Think about it: There are more ways to get a 20 than there are to get a 7 or a 35. Same thing with rolling 2 die.

Re: My Job Interview at Google

#55
post #35

Earlier quoted context omitted.

It's actually * and &. ;-) Don't interview for positions in languages you've forgotten, then, or brush up and re-learn stuff before the interview. It's like riding a bike...it comes back to you. Not being able to remember pointer syntax is a serious problem if you're being hired to program in C. I can understand why they'd want to weed out anyone who can't get that, particularly given how many candidates they have.

lol, thanks. I could have said x[i] is the same as ^(x + i) and really thought that was the correct syntax. The problem is I have used enough languages and dialects that I really can't brush up on it all. I just say if it's been five years, let me break out my cheet sheet for that stuff. PS: Ok, if it was really just a C job of course I would focus on that. Edit: Dammit it is like riding a bike. I have been having C…

My solution to this problem was to make up sets of editor macros for the various languages I've used, with the same key chords producing the same semantics in varying syntax.

Re: My Job Interview at Google

#57
post #54
post #40

Earlier quoted context omitted.

Execute f 7 times, add all numbers, call that x. Then you do mod(x,7)+1, and you get a random number between 1 and 7. If the original function was unbiased, this one is going to be unbiased too.

This won't work. f gives 1 to 5. 7 * f gives 7 to 35. But 7 to 35 will not be evenly generated. Think about it: There are more ways to get a 20 than there are to get a 7 or a 35. Same thing with rolling 2 die.

That was my second thought too (my first thought was to upvote the comment), but at least in the 2-die case, the modulus takes care of it. If you work out the probabilities, the chance of getting 0mod2 = 1/36 (2) + 3/36 (4) + 5/36 (6) + 5/36 (8) + 3/36 (10) + 1/36 (12) = 18/36 = 1/2. Same goes for getting 1mod2. So you end up with a fair result even though the chances for each individual outcome are biased.

I didn't want to go through all 5^7 possibilities for the 7-die case, but I figured it's likely enough that he's right that I'd keep my mouth shut.

Re: My Job Interview at Google

#58
post #54
post #40

Earlier quoted context omitted.

Execute f 7 times, add all numbers, call that x. Then you do mod(x,7)+1, and you get a random number between 1 and 7. If the original function was unbiased, this one is going to be unbiased too.

This won't work. f gives 1 to 5. 7 * f gives 7 to 35. But 7 to 35 will not be evenly generated. Think about it: There are more ways to get a 20 than there are to get a 7 or a 35. Same thing with rolling 2 die.

f * f gives you 25 boxes, number 11, 12, ... 15, 21,...25...55. Assign 3 each of 21 of those to 1..7. If f * f doesn't fall into one of those 21 boxes, repeat until it does.

Re: My Job Interview at Google

#59

Could anyone point me on how to solve this(either a solution or preferrably a pointer on how to get to it): "Q: Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7." First I thought it was simple but the I got stuck, maybe I'm just tired. No matter how I twsit and turn it I seem to get only an even distribution over 5 numbers.

Here's my shot at a solution:

;; * SPOILER? *

  (defun rand7 ()
    (loop (let ((result (+ (1- (rand5))
	   		   (1- (rand5)))))
	    (if (
;; * SPOILER *

edit: If it doesn't work I'd like to know why...

Re: My Job Interview at Google

#60

Could anyone point me on how to solve this(either a solution or preferrably a pointer on how to get to it): "Q: Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7." First I thought it was simple but the I got stuck, maybe I'm just tired. No matter how I twsit and turn it I seem to get only an even distribution over 5 numbers.

If you want a spoiler:

http://ariya.blogspot.com/2007/11/random-number-15-to-17.htm...

He gives a few different ways to solve it, most with uniform distribution.

Post reply on HN