# [Community puzzle] Google Interview - The Two Egg Problem

1 Like

Well, If you donâ€™t know the trick, Itâ€™s rather hard to find (thatâ€™s probably why itâ€™s used in google interviews). Once you know the trick, 5 lines of code are enough to solve it so no real programming skills involved. Itâ€™s more a logic/math problem than a real programming puzzle IMO.

Just one line for me.

1 Like

Hi,

I donâ€™t really get this one.

When it says you get two eggs, does it mean you get to only break one egg and then you have to make sure the second one doesnâ€™t break until you find the right floor ?
Or does it mean you get to drop eggs 2 by 2 until you succeed ?

You have 2 eggs, thatâ€™s all ! If you break them all before finding the right floor, you lose!

The title of the puzzle drew my interest, and I solved it.

The description of the problem wasnâ€™t very clear, so I had to google about the problem to understand the problem statement.

It would be hard to solve the problem without any hints, but looking at the test cases I saw the pattern to the solution.

Hi,

Thanks for the help people !
I also had to look the problem up to solve it, I definitely wouldnâ€™t have thought of the answer by myself.

technically, there is no other function call mentioned that we can use to decide on first egg drop whether it is success or failure. there should be only one cout in the program. I am stuck on how this is going to help us decide whether first drop is successsful or not

You donâ€™t need this information, just focus on what strategy you have to use to be effective in the worst cases.

Can the egg be broken if it dropped from the first floor?
If yes, then there is no the highest floor an egg can be dropped from without breaking.
If not, then in the case of a two-floor building is enough to drop once.

3 Likes

Exatly, weird problem statement.

1 Like

I googled it (cautiosly, didnâ€™t want to find the solution) and one of the pages states â€śEggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100 th floor.Both eggs are identical.â€ť So â€śOne of the floors is the highest floor an egg can be dropped from without breaking.â€ť is a very bad problem statement.

1 Like

The problem statement is wrong, or the test-cases and answers are wrong!

â€śA building has N floors. One of the floors is the highest floor an egg can be dropped from without breaking.â€ť

If N=2, then the building has 2 floors. One of them will be the answer. I only need one drop. I drop it from the top floor of the two. If it breaks then the answer was â€śbottom floorâ€ť. If it doesnâ€™t break then the answer was â€śtop floorâ€ť.

But the test case says 2 drops is the answer. So frustrating! Please fix it.

2 Likes

based on results, egg might break on first floor so u need 2 drops

2 Likes

If it doesnt break on the first floor, how do you know it wont break on the second floor? It is asking for worst case answer, so 2 is the correct answer.

If you choose to drop it on the first floor, then worst case is 2, but one can choose to drop the egg from second floor and deduce the answer from the result of that single drop.

If it breaks then the answer was â€śbottom floorâ€ť. If it doesnâ€™t break then the answer was â€śtop floorâ€ť.

ok, so if it breaks on the 1st floor what does that mean that the 0th floor ?!? is the " highest floor an egg can be dropped from without breaking".

The statement says :
â€śA building has N floors. One of the floors is the highest floor an egg can be dropped from without breaking.â€ť

If the egg can break on the 1st floor, then the building has N floors (1st to Nth) + the 0th floor, so it has in fact N + 1 floors not N.

You say â€śBased on the results â€¦â€ť, but thatâ€™s exactly the point : the results are false because they contradict the statement.

2 Likes

whatâ€™s the function call for testing a floor? iâ€™m missing something hereâ€¦

Exactly what I was thinking.

I agree: with two floors the solution should be one:

• You drop one egg from floor #2
=> If it breaks then answer is floor #1
=> if it does not then answer is floor #2

Iâ€™ll check with the author to see if there is a problem in the statement or with test case #5 or if it is just meâ€¦

1 Like