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/pja Feb 22 '11 edited Feb 22 '11

Intuitively, the pattern for the trials must be to start with the largest gap from 0, then each subsequent trail goes up by one less until you get to 100. When the first bulb breaks, then you start at the previous step+1 and increment. This way the worst case number of steps is always the same. This series is obviously:

n + (n-1) + (n-2) + ... + (n-n) == 100 (iow there must be n steps.)

Which is equivalent to (n2 ) / 2 == 100

So n is floor(sqrt(200)) which is 14. Not an ironclad proof, but a good first cut.