Total Pageviews

Thursday, May 31, 2012

Solution of "Egg drop problem" asked by Google.

Problem:

There is a building of 100 floors. If an egg drops from the Nth floor or above it will break. If it's dropped from any floor below, it will not break. You're given 2 eggs. Find N, while minimizing the number of drops for the worst case.

Solution:

We go to
Floor14 and drop first egg. If it breaks try 2nd from 01, 02,....13 i.e. This takes 14 steps maximum.
then 27 and drop first egg. If it breaks try 2nd from 15, 16,....26 i.e. This takes 14 steps maximum.
then 39 and drop first egg. If it breaks try 2nd from 28, 29,....38 i.e. This takes 14 steps maximum.
then 50 and drop first egg. If it breaks try 2nd from 40, 41,....49 i.e. This takes 14 steps maximum.
then 60 and drop first egg. If it breaks try 2nd from 51, 52,....59 i.e. This takes 14 steps maximum.
then 69 and drop first egg. If it breaks try 2nd from 61, 62,....68 i.e. This takes 14 steps maximum.
then 77 and drop first egg. If it breaks try 2nd from 70, 71,....76 i.e. This takes 14 steps maximum.
then 84 and drop first egg. If it breaks try 2nd from 78, 79,....83 i.e. This takes 14 steps maximum.
then 90 and drop first egg. If it breaks try 2nd from 85, 66,....89 i.e. This takes 14 steps maximum.
then 95 and drop first egg. If it breaks try 2nd from 91, 92,....94 i.e. This takes 14 steps maximum.
then 99 and drop first egg. If it breaks try 2nd from 96, 97,....98 i.e. This takes 14 steps maximum.
then 100.


--
Thanks & Regards
Manish Kumar


No comments:

Post a Comment