Interview Question for Software Engineer / Developers


Team: Java
Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

Start from bottom of the building and find which story one of the gg breaks..for example egg 1 breaks at 4th story..now drop egg 2 at 4-1 i.e. 3rd story if it breaks then egg one was toughest else try 4th if it breaks both toughest else egg 2 is toughest.

- Anonymous July 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if the 1st egg breaks at 1st floor..???

- Anonymous July 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Assuming there is always a solution, as mentioned in some of the answers above, 2nd egg is tougher. Also on the same lines, if first egg does not break even at 50th floor, 1st one is tougher.

- kannepallianil July 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If it breaks at he first floor, throw the second one from 2nd floor. If it doesn't break, then 2nd egg is stronger. Otherwise, we can't figure out which one is stronger.

- alex October 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Throw both eggs from everyfloor starting at 1st floor.

Floor Eggs Thrown Broken
1 2 2 0
2 2 2 0
3 2 2 0
4 2 2 0
5 2 2 0
6 2 2 1 -Other egg is the strongest

If both eggs break from a particular floor, then both of them have the same strength.

- Piyush (pcclm.com) March 25, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

first try at 10th floor if egg1 breaks,then try egg2 at 11th floor if it breaks then egg1 is toughest else egg 2 is toughest
if egg1 not breaks at 10th , try at 19th , if egg1 breaks then try egg2 at 20th floor if it breaks then egg1 is toughest else egg 2 is toughest
if egg1 not breaks at 19th , try at 27th , if egg1 breaks then try egg2 at 28th floor if it breaks then egg1 is toughest else egg 2 is toughest

do this again for 34th,40th,45th,49th floors in sequence
in worst case you require 8 attemts

- Anonymous July 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

let egg1 in your case be unbreakable till 4th flloor and egg 2 be unbreakable till floor 8, ull get the wrong ans!
so wrong explanation.

- anon August 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

:The best answer:
I shall generalize the solution for a general "n storeyed building"
Divide the interval of checking as sqrt(n)
Check for 1st egg to break at 1*sqrt(n) , 2*sqrt(n) , 3*sqrt(n) , .....until u reach "n"
Suppose it breaks at i*sqrt(n)
then check for the second egg at (i-1)*sqrt(n) , (i-1)*sqrt(n) +1 , (i-1)*sqrt(n) +2 , ..... , i*sqrt(n)

This gives the answer in O( sqrt(n) ) time which shall be least of all

- Anonymous July 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

may i know why did you choose sqrt(n) ??

- james August 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

But why do we even want to find it? Just make an omelet with both

- s July 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

the only answer that has the right idea

- lol February 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

just hit two egg among each other which one strong will stay unbroken... attempt is one

- Deepak@teaser July 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hit both the eggs to each other. Only one egg will be broken and the unbroken egg will be the strongest.

- Sunny September 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about we don't care about the building and just smash the eggs against each other with equal force? The strongest will survive.

- Mathieu Dumont December 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Absolutely incorrect.
1. The force of the first egg against the second is always equal by value (and opposite by direction) to the force of the second egg against the first - third law of Newton.
2. If you thrust two eggs together with some force, there can be one of the three outputs:
a). Both eggs break.
b). None break.
c) One of them breaks, the other not.
You will have to try [potentially] large amount of different forces to find out which egg is tougher.

- Leo July 27, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The problem statement is ill defined. The problem is not to "find the toughest egg," but instead to find out the highest floor from which an egg will not break when dropped out of a window.

If one is to learn an elegant solution best suited to the intended audience it's best to start with a better definition - found here: tinyurl<dot>com/lglon3g

- mayorofbelmar March 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why should we throw it down? We can just hit them against each other and the one that cracks first is the weaker one.

- Laura February 10, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 3 vote

I first thought this was the classic two egg puzzle (classic-puzzles.blogspot.com/2006/12/google-interview-puzzle-2-egg-problem.html), but it turns out this one is slightly different, so I am changing the solution:

Drop the egg at every other floor starting at 2nd, i.e., 2, 4, 6, 8, ...
if it breaks at that ith level, drop the second egg at i-1th floor, if the second egg breaks, then first is the toughest, second otherwise.

- oOZz July 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This isn't the same question. The question asks to find 'the toughest egg', while your question posits identical eggs. The solution will not work. For example, if the first egg breaks on the 10th floor, you have no information other than that it is less tough than being able to stand a tenth-floor fall, meaning if the second egg is also in that range you will not be able to tell which is tougher.

- Anonymous July 01, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Up you're right, it's not the same problem. Unfortunately it doesn't let me delete it, so I updated the solution. I gotta tell you though, this version has no originality.

- oOZz July 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if both the egg break at ith level..???

- Anonymous July 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Dropping at alternate levels wont work.
I mean u drop 1st egg at 8th floor and it breaks, then if you drop 2nd egg from n-2 which is 6th floor and it breaks, easy the first egg was the tough one.

But if it does not there are 2 things, it does not break at 6th floor so u might to try it now at 7th floor, if it not break there, fine we can still keep adding 1 floor to it. But if breaks at 7th floor, that does not prove egg 1 is weaker since we never tried it at 7th floor which would make them equal or egg 1 might have won.

The only answer i see here is go to each floor, once you find the floor where egg 1 breaks, try n-1, n and n+1 for the possible answers.

- Vaibhav July 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

One egg is tougher than the other. That's implied in the question, because the question is asking which one is the toughest.

Therefore, they can't break on the same floor, because then that means they are equally tough and there won't be a solution.

- oOZz July 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sol:
Through first egg from 7th floor.......... if egg got broken... start throwing from 1st to 6th
If egg was not broken from 7th floor... now through from 14th floor..... then 21.... 28....35....49

Complexity:
In worst case only 8 attempt is required.

- PKT July 18, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

In worst case 12 eggs need to be wasted. (2 eggs in best case)
:)

- SMT July 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Sol:
Through first egg from 7th floor.......... if egg got broken... start throwing from 1st to 6th
If egg was not broken from 7th floor... now through from 14th floor..... then 21.... 28....35....49

Complexity:
In worst case only 8 attempt is required.

- PKT July 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

use dynamic programming approach to solve it, search on wikipedia

- shsf July 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

use dynamic programming approach to solve it, search on wikipedia

- shsf July 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

use dynamic programming approach to solve it, search on wikipedia

- shsf July 07, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More