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
What is pointers in c?
Write a program to print numbers from 1 to 100 without using loop in c?
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);
How can I insert or delete a line (or record) in the middle of a file?
Explain how can type-insensitive macros be created?
Can include files be nested? How many levels deep can include files be nested?
Why c is procedure oriented?
What is type qualifiers?
Difference between MAC vs. IP Addressing
What is difference between constant pointer and constant variable?
How can I copy just a portion of a string?
Write programs for String Reversal & Palindrome check
largest Of three Number using without if condition?
Explain how can I convert a string to a number?
What does return 1 means in c?