There is a 100-story building and you are given two eggs.
The eggs (and the building) have an interesting property
that if you throw the egg from a floor number less than X,
it will not break. And it will always brake if the floor
number is equal or greater than X. Assuming that you can
reuse the eggs which didn't broke; you got to find X in a
minimal number of throws. Give an algorithm to find X in
minimal number of throws.

Answers were Sorted based on User's Feedback



There is a 100-story building and you are given two eggs. The eggs (and the building) have an inte..

Answer / j1g54w h4ck3r

Find a number n such that n(n+1)/2>=99. (You'll know why
later). n=14 in this case.
Throw one egg from 14th floor.
If it breaks,
start throwing the other egg starting from the 1st floor,
bottom up till it breaks. Max no of throws(worst case)=1+13=14.
else Throw the egg from (14+13)= 27th floor. If it breaks
start throwing the other egg from 15th floor bottom up. Max
no of throws=2+12=14.
Continue till you find the floor.
In the worst case, you'll have to do 14trials compared to
the rather large figures provided by other solutions.
Regards,
J1g54w H4ck3r

Is This Answer Correct ?    71 Yes 11 No

There is a 100-story building and you are given two eggs. The eggs (and the building) have an inte..

Answer / chalimar

We are confused by the telling of this puzzle. Does the question really ask the minimum number of throws, or the minimum number of eggs? The second possibility is suggested by the clause, "Assuming that you can reuse the eggs which didn't [brake]." One answer here has made that presumption, starting at the first floor and going up floor by floor.

Is This Answer Correct ?    0 Yes 18 No

There is a 100-story building and you are given two eggs. The eggs (and the building) have an inte..

Answer / ashutosh tiwari

Go to the middle floor, 50 in this case; drop egg, if breaks
go to middle of 1st and 50th i.e. 25th floor otherwise go to
middle of 50 and 100 i.e. 75th floor.

Keep on repeating the method to find the floor in minimum
iteration or egg breaking.

Hope this helps..!!!

Is This Answer Correct ?    5 Yes 25 No

There is a 100-story building and you are given two eggs. The eggs (and the building) have an inte..

Answer / the practitioner

Just start on the first floor and throw the egg. If it
breaks then X=1
If not then go to the second floor and throw the egg. If it
breaks then X=2
If not then go to the third floor and throw the egg. If it
breaks then X=3
If not then keep doing that and the floor it breaks on is
the floor that X equals.
But really, in real life, a real egg would break from 3
feet.

Is This Answer Correct ?    0 Yes 31 No

There is a 100-story building and you are given two eggs. The eggs (and the building) have an inte..

Answer / basvaraj s pinna

We should start from the second floor to identify the X
floor.

Step 1. Throw the one egg from second floor,
if it breaks in second floor then go to first floor,
through remaining one from the first floor
if it breaks on the first floor then X=1
else
X=2

If does not break in second floor, goto fourth floor and
throw the egg
if it breaks in fourth floor then go to third floor,
through the remaining egg from the third floor
if it breaks on the third floor then X=3
else
X=4

Similarly we should run floor = floor + 2, till one egg
breaks,

floor = floor + 2
if one egg breaks at floor then
Set currentfloor = floor -1 and check for remaining egg
throw from currentfloor, if egg breaks at currentfloor,
then X= currentfloor else X=floor
Else
floor = floor + 2

do until floor =100

Is This Answer Correct ?    10 Yes 55 No

Post New Answer

More C Interview Questions

What is far pointer in c?

0 Answers  


When should you not use a type cast?

0 Answers  


What is the purpose of & in scanf?

0 Answers  


WHY DO WE USE A TERMINATOR IN C LANGUAGE?

2 Answers  


Why is c so important?

0 Answers  






how to write palindrome program?

3 Answers  


Write the program for displaying the ten most frequent words in a file such that your program should be efficient in all complexity measures.

3 Answers   Google,


Where we use clrscr in c?

0 Answers  


Why does everyone say not to use scanf? What should I use instead?

0 Answers  


Can you subtract pointers from each other? Why would you?

0 Answers  


What is output of the following program ? main() { i = 1; printf("%d %d %d\n",i,i++,i++); }

9 Answers   CTS, Wipro,


Differentiate between #include<...> and #include '...'

0 Answers  


Categories