Amazon.com Interview Question
1,566 Interview Reviews |
Back to all Amazon.com Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Development Engineer Intern at Amazon.com:
(following the previous one) You got only TWO baby bottle sample. You would like to know the max height you can drop it without breaking the bottle. Let set the unit as 1 foot. And the highest height you can reach is at N feet. So how would you find the (max) safe height? (This is the one I think is kind of brain-teaser one.)
| Tags: | brain teaser See more , See less 8 |
See more for this Amazon.com Software Development Engineer Intern Interview
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (8)
0 of 1 people found this helpful
1. use the O(log n) approach until the bottle breaks to find better bounds
2. use linear search on those new bounds to find the answer
So worst case is O(n/2) best case is O(log n)
Helpful Answer?
Yes |
No
Inappropriate?
1 of 2 people found this helpful
Helpful Answer?
Yes |
No
Inappropriate?
4 of 4 people found this helpful
Helpful Answer?
Yes |
No
Inappropriate?
linear search with second bottle
O(n^1/2) complexity
Helpful Answer?
Yes |
No
Inappropriate?
6 of 7 people found this helpful
Assume you have a number, D, that is the max bottle drops you can use to find the answer.
To do this you would start at floor D and drop the bottle. If it breaks, then you do a linear search from floor 0 to D with the other bottle (thus finding the solution in, at most, D attempts).
If it doesn't break, move up D-1 floors. It must be D-1 because if the bottle breaks, you will only have D-1 attempts left to do the linear search. This is because you used one attempt back at the previous floor. If it breaks you do the linear search from floor D to your current floor.
You repeat this process (always moving up one less floor) until you run out of attempts.
If you write out this in an equation, the highest floor you can get to is given by the sum:
D(D+1)/2 >= N
Solve for whatever particular N, and you get the best possible D.
For example, on a 100 story building you can find the highest floor with at most 14 drops.
Helpful Answer?
Yes |
No
Inappropriate?
1 of 2 people found this helpful
Helpful Answer?
Yes |
No
Inappropriate?
1 of 1 people found this helpful
N/x + x. Objective is to minimize x. So, get differential and equate to 0. x = N^(1/2)
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up



0 of 1 people found this helpful
by Interview Candidate:
My interviewer insist there exists a better answer (in terms of time complexity). But he refuse to tell me the answer nor hint, for example, what will that time complexity be in this solution. I wish someone can help on this problem.