100 floors with 2 eggs puzzle

Problem Statement:

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.

Give an Algorithm to find N, while minimizing the number of drops for the worst case.

Solution:

The Problem comes with a general equation as X(Max Number of floors) = n*n;

So in this case for example, X= 100 Floors( => n=10)

now use the value n to traverse. This means that drop the first egg from 10th floor, then 20th floor, then 30th and so on up to 90.

The floor from which it breaks, say 60th, then go back 10 floors and try each floor to find N.

After Floor 90, Start moving 1 by 1.

Worst case scenario:

eggs break at 99th floor.

Egg drops: 10 -> 20 -> 30 -> 40 -> 50 -> 60 -> 70 -> 80 -> 90 -> 91 -> 92 -> 93 -> 94 -> 95 -> 96 -> 97 -> 98 -> 99

Max Attempts: 18

0 Replies to “100 floors with 2 eggs puzzle”

Leave a Reply