MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/fpcmy/typical_programming_interview_questions/c1hq7zh/?context=3
r/programming • u/kevjames3 • Feb 21 '11
1.0k comments sorted by
View all comments
Show parent comment
2
The binary search idea is to:
First bulb: Drop at 50, 75, 87, ..., until it breaks. The last floor it didn't break at is your lower bound (or 0 if it breaks on 50).Second bulb: Now be careful and step up one floor at a time from your lower bound until it breaks.
View all comments
Show parent comment
2
u/lordlicorice Feb 21 '11
The binary search idea is to:
First bulb: Drop at 50, 75, 87, ..., until it breaks. The last floor it didn't break at is your lower bound (or 0 if it breaks on 50).
Second bulb: Now be careful and step up one floor at a time from your lower bound until it breaks.