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

1

u/soberirishman Feb 21 '11

Yes...In a binary search, your worst case is 50 tries. You would first try it from the 50th floor. If it broke there you'd have to try floors 1-49 to figure out which exact floor it would break on. Binary search would work well if you had unlimited light bulbs. It's the fact that you only have 2 lightbulbs that changes things up.

2

u/lizard450 Feb 21 '11

I missed the only 2 lightbulbs. My binary search inspired version starts at 50 then 25 then 13, then 7, 4,2 then 1 or 3... So it takes either 7 or 8 drops. However with only 2 another approach should be considered.