# 2 Eggs and 100 floor Google Classic question

1,318.5K Views

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

How many drops you need to make?
What strategy should you adopt to minimize the number egg drops it takes to find the solution?

Anand Guru Asked on 12th July 2015 in

We want to minimize the number of drops for the worst case, while still using an approach that works well for other scenarios. So, how can we do this? Well, we should rephrase that question and ask ourselves what is really holding us back here? The main reason why it takes such a large number of drops in the worst case with our approach above (19 drops) is because in order to test out the higher floors of the building we have to start at the lower floors of the building, and at that point we have already used a large number of drops just to get to that point.

What we should try to get with our next approach is to try to reduce the worst case scenario by trying to make all possible scenarios take the same number of drops.

What if we tried to reduce the number of drops that would be required with the linear search (with the 2nd egg) after we get to one of the higher floors? This way we counteract the fact that getting to the higher floor took so many drops, and if we use less drops for the linear search we are balancing out the worst case.

Let’s try to figure this out using some simple algebra. Suppose we drop an egg from floor x. If the egg breaks, then we would have to go through the previous x-1 floors one by one using a linear search.

But, if the egg doesn’t break, in our original algorithm we would go up x floors to find the next floor to test from. Why not just go up x-1 floors instead of x floors? This would save us 1 drop if we have to do a linear search with the 2nd egg whenever the first egg breaks – because we would be doing the linear search from floors x+1 to floor ( (x+1) + (x-1)) instead of floors x+1 to floor (x+1) + x. So, that is 1 less egg drop. This means that the next floor that should be attempted to drop from is x + (x-1) if the egg does not break from floor x. And by the same reasoning the floor after that would be x + (x-1) + (x-2) if the egg does not break on floor x + (x-1).

This would go on to form a series that looks like this:

```x + (x-1) + (x-2) + (x-3) + ... + 1
```

The series above is what’s called a triangular series which is equal to x(x+1)/2. Because there are 100 floors in the building, we set the sum equal to 100 to solve for x:

```x(x+1)/2 = 100
```

When the sum of the series above equals 100, we get x = 13.651, which rounds up to 14. This means that we should start from floor 14 (which is our x) and then move up x-1 (13) floors to floor 27 if the egg doesn’t break and then move up x-2 (12) floors to floor 39 and so on if the egg still does not break.

This is the number of drops required as we move up the floors in the building:

Drop
Floor
#1 14
#2 27
#3 39
#4 50
#5 60
#6 69
#7 77
#8 84
#9 90
#10 95
#11 99
#12 100

## 2 Eggs 100 Floors Worst Case Solution

The solution for the worst case in this scenario occurs when the threshold floor is floor number 14 – because we will drop the first egg on floor 14, and it will break. Then we have to test floors 1-13 with the 2nd egg to see where the egg breaks again, and the egg will not break on any of those floors. But since the egg broke on the floor 14, we can conclude that the threshold floor is floor number 14.

Anand Guru Answered on 12th July 2015.

First thought which comes to our mind is to use binary search, we first drop Egg#1 from 50th floor, if it does not break, then try the middle of second half, if breaks then we have to try each floor in first half. But this will give worst case number of drops as 50(if it brakes on 50th floor, then we have to try from 1 to 49 floors sequentially).

Second thought is to try xth floor then 2xth floor till 100th, in this case worst case time will be (100/x)+(x-1). worst case will be when Egg #1 breaks at 100th floor then we have to try Egg #2 from (100-x)th to 99th floors. In (100/x) + (x-1) equation, with increase in x, 100/x decreases while (x-1) increases, thus we can minimize it when 100/x = (x-1), this gives x ~10, which gives worst case number as 19 drops.

But increasing the floor every time by x is not a very nice idea, as with each new increase in Egg #1 drop, we should decrease Egg #2 drops to minimize worst case number. so if we drop Egg #1 from xth floor initially, then in next turn we should try x + (x-1)th floor(to keep the worst case number same).
Thus we can say X + (x-1) + (x-2)…1 = 100
X(X+1)/2 = 100 => X=14.

So we should drop Egg #1 from 14th, then 27th, then 39th and so on.

SherlockHolmes Expert Answered on 21st August 2015.

In worst case it will take 14 egg drops to find the value of N.

This follows the below logic.
Say, the egg breaks at floor n we try to find out by going (N-1) till the first floor by doing linear search.
Say for example, I throw the egg from 10th floor, and it breaks, I wíll go to floor 1 to 9 to find out the floor..
Then I would try the same logic for every 10 floors thereby setting a worst case scenario of 19 chances.. I.e. 10,20,30,40,50,60,70,80,90,100,91,92,93,94,95,96,97,98,99

To find optimum solution, let’s try this:
If for every n, egg doesnt break, instead of going to next n, go to N-1, this would save us one drop as we are doing a linear search with second egg when egg1 breaks…
So the series would look something like this..
N + (N-1) + (N-2) + (N-3) +…+ 1

Now this is a series which is equal to N(N+1)/2

Now since it is given that the egg may or may not break from 100th floor..

We can write it as..

N(N+1)/2>=100
And n=14(approx)

So we should start from 14 then move up N-1 to 13 floor I.e. 27,39…

So the floors from where the drop needs to be done are: 14,27,39,50,60,69,77,84,90,95,99,100

So the answer is 14

amol Scholar Answered on 21st August 2015.

In the worst case, 7  eggs are required to solve the value of N. We can do this problem by using BINARY SEARCH TREE.  Initially we have to start from 50th floor.  If egg  broke, we have to go for 25th floor, else go for 75th floor. Now, we have to leave the egg from 25th floor. If egg broke, we have to go for 13th floor else, go for 19th floor. Similarly on 75th floor too..

If yes, go to (Lower Bound+ Middle Term)/2

else , (Middle Term + Upper Bound)/2

By within maximum of 6-7 steps, we can find the answer.

yes                    50                no

yes    25   No                                                        yes   75 no

yes    13   no                       38

yes  7    No                19

By this we have to draw binary search tree.

on 5th September 2015.

But we can break 2 eggs at maximum. So going to 25th floor after 50 is not possible.

on 2nd October 2015.

Yes, Sarthak is right,

We have 2 eggs only and if we start from 50th floor and if egg broke,
we’ll have to start from Floor 1 to 49
That will make worst case of 51 TRIALS.

on 3rd October 2015.

Drop one egg from the first floor. If it doesn’t break drop it from the second floor. Keep dropping until the egg breaks. The floor the egg was dropped from when it broke is N. You broke one egg and have one egg left over.

you can reduce the number of drops by starting at say 10, but you’ll have to sacrifice one egg

Vega Default Answered on 24th September 2015.

Drop one egg from the second floor and keep going upwards until the egg breaks.
Second floor because all eggs thrown below nth floor doesnt break.

Balesh Talapady Starter Answered on 15th November 2015.

We need minimum number of attempts

on 15th February 2020.

The answer is much simpler, and it is N drops. Let’s assume that the egg breaks at floor 20, then you would make a drop on floor 1, it will not break, and then again on floor 2 all the way to floor 20. On the 20th floor it will break, here we know what floor the egg break (which is also going to be the Nth drop) and we will still have one egg.

leonarther16th Default Answered on 11th February 2016.

Start from the 2nd floor and then go to +2 floor every time to try the next. If first egg breaks at any level then just test the 2nd egg on the -1 floor from the current level. For example….. go in this way ….. 2nd , 4th, 6th, 8th, 10th, 12th, 14th and so on….. and lets consider the egg breaks at 14th floor then try the 2nd egg at 13th floor and if it not breaks at 13 than  it is the maximum level and after that the egg will break.

aidenstoker Starter Answered on 3rd June 2016.

its an egg guys calm down, it will even break dropping from 2 feet above the ground, as u r using oops technologies, so think accordingly.

ashishPatel Starter Answered on 30th June 2016.

Start from floor 10  and go in increments of 10 with the first egg. If it breaks then use the second egg from floor 1 to 9. The worst case scenario is 10 + 9 = 19.

jaiganesh Ads Starter Answered on 10th July 2016.

We have only 2 eggs if both eggs are broke.  we can’t use more eggs

this is actual algorithm to find the Nth step

1. We need to start from 1st floor and throw the egg
2. If egg didn’t broke  move to 3rd floor (+2)
3. and we can continue till 99 if egg didn’t break in 99th floor then 100th floor is Nth
4. if the egg break in anywhere(ex: 57) we need to check x-1 floor too with another egg ( so 56th)
5. if the egg break on 56th floor then 56 floor is N otherwise 57 is  N
Sajan Curious Answered on 2nd September 2016.

• ## More puzzles to try-

• ### coins in line riddle

You have 10 coins….arrange them in 4 straight lines such that each line contains 4 coins, without picking up the ...Read More »
• ### Trivia Question

why number 8549176320 is one of a kind?Read More »
• ### It has no heart but yet it lives riddle

It has no heart but yet it lives. If it does not live then you won’t live. It does not ...Read More »
• ### Largest amount of money change

What’s the largest amount of money you can have in change and still not have change for a dollar?Read More »
• ### Andrew sees a very rare bird named and dead puzzle

Andrew sees a very rare bird named “Ruppell’s vulture“. Soon Andrew was dead. Can you explain the mystery Mr. Sherlock?Read More »
• ### Rounding Off Numbers

Find a 9-digit number, which you will gradually round off starting with units, then tenth, hundred etc., until you get ...Read More »
• ### Queue order

Seven kids are in line for a carnival ride. Third in line is Joe, and two spots ahead of him ...Read More »
• ### Lying World war story riddle

Two friends Smith and Andrew were talking about bravery of their families. Smith told great stories about his courageous grandfather ...Read More »
• ### Probable riddle

A jar contains one hundred marbles, each of which may be white or black. You pull out 100 marbles with ...Read More »
• ### 2 piles of 100 coins puzzle

You have 100 coins laying flat on a table, each with a head side and a tail side. 10 of ...Read More »
• ### What is 4 and 5?

Two is company and 3 is a crowd. What is 4 and 5?Read More »
• ### Examination Probability puzzle

What is the least number of Candidates needed to appear in a examination of 300 marks, such that there is ...Read More »
• ### What does 1111/TIME mean

What does 1111/TIME meanRead More »
• ### What is the code ?

A man desired to get into his work building, however he had forgotten his code.  However, he did recollect five ...Read More »
• ### How much is the ring worth?

At an eBay auction, a woman’s ring and a filigree jewelry box with a hand-painted ceramic top are on sale ...Read More »
• ### What happened to Angel and Dory

Angel and Dory were found on the ground gasping for air surrounded by glass and water. The person who found ...Read More »
• ### How many would he have in the first field?

A farmer has three fields. One of them has 3 bundles of hay, another has 4, and the last has ...Read More »
• ### Can you cut and reassemble a square so that you create a red cross of the same volume?

Can you cut and reassemble a square so that you create a red cross of the same volume?Read More »
• ### Polar Bear riddle

You are on holidays and wake up in the morning, stand up, and look South. You look to the left ...Read More »
• ### Has two eyes riddle

It is flat as a leaf, round as a ring, Has two eyes, can not see a thing. What is ...Read More »