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.

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is pointers in c?

774


Write a program to print numbers from 1 to 100 without using loop in c?

749


What will the code below print when it is executed?   int x = 3, y = 4;         if (x = 4)                 y = 5;         else                 y = 2;         printf ("x=%d, y=%d ",x,y);

1446


How can I insert or delete a line (or record) in the middle of a file?

665


Explain how can type-insensitive macros be created?

674






Can include files be nested? How many levels deep can include files be nested?

739


Why c is procedure oriented?

672


What is type qualifiers?

767


Difference between MAC vs. IP Addressing

727


What is difference between constant pointer and constant variable?

741


How can I copy just a portion of a string?

951


Write programs for String Reversal & Palindrome check

690


largest Of three Number using without if condition?

1124


Explain how can I convert a string to a number?

724


What does return 1 means in c?

666