Feel free to send your feedback or ask some help here!
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.
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.
Exatly, weird problem statement.
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.
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.
based on results, egg might break on first floor so u need 2 drops
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.
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…