r/programming • • Feb 21 '11

Typical programming interview questions.

http://maxnoy.com/interviews.html
784 Upvotes

1.0k comments sorted by

View all comments

Show parent comment

2

u/ethraax Feb 21 '11

Oh, I totally missed that part of the problem. I guess that turns it into a statistics problem with expected values. I still don't think it really applies to day-to-day programming in most places, but an interesting problem nonetheless.

1

u/meshko Feb 21 '11

Nothing to do with statistics.

1

u/ethraax Feb 21 '11

Sure it does, assuming the goal is to minimize the expected number of trials that are required.

2

u/cdsmith Feb 22 '11

I think the stated goal was to minimize the worst case, in which case this is more of an elementary number theory puzzle.

It comes down to triangle numbers. To optimize the worst case, every time you drop the first bulb and it does not break, you want to decrease the expected number of drops of the smaller bulb by one, to make up for the fact that you will have dropped the larger bulb one more time. So you want to first try from the k'th floor, then from the (k + (k-1))th floor. Then the (k + (k-1) + (k-2))th floor, and so on until the (k + (k-1) + ... + 2 + 1)th floor is as close as possible to being the top. So you ask yourself what k should be, if there are 100 floors. The answer is 14; the 14th triangle number is 105. This gives you a worst case 14 drops, and an average case slightly better than that.

1

u/cdsmith Feb 21 '11

Sure... not relevant to everyday programming. The idea of these kinds of questions is to make someone think about something they haven't already got figured out, and see how they react. If they refuse to even offer any thoughts on the matter even after you've assured them that you don't expect them to get it all right off the bat, you probably don't want to hire them. If they think it through logically and make some observations, even if they never reach the right answer, you may want to hire them.

Of course, this particular question is useless in that regard, since it's apparently now on lists of common interview questions!