Bloomberg LP Interview Question for Software Engineer / Developers






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

It can be done in 13 drops...

http://www.cs.umd.edu/~gordon/ysp/egg.pdf

- Anonymous August 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thank you for the link, it's a very good description!
Just one simple correction;
The link states that it can be done in 14 or fewer drops, not 13 as suggested by this post. This is because in the situation that the first egg breaks at your first drop on 14 then you have a possible 13 more drops (1-13) to see if the egg breaks. That means if the egg breaks on floor 13 then you will have 14 drops total including the first egg. =)

- Nagash August 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It can be done in 14, and that can be proved to be optimal.

If I remember correctly, the sequence of floor choices is:

14,14+13,14+13+12,14+13+12+11,...

- T May 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I solved it some while ago.
The solution is, as you can see, DP.

For B=2, there's a nice formula (you can see it in the assert - the condition that I put there):
F max = (D * (D+1))/2

- Marian May 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I paste the code again, preserving spaces:

long[][] fMaxTable = new long[MAX_D + 1][MAX_B + 1];
		
		for (int i = 1; i <= MAX_B; i++)
			fMaxTable[1][i] = 1;
		
		for (int i = 1; i <= MAX_D; i++)
			fMaxTable[i][1] = i;
		
		for (int d = 2; d <= MAX_D; d++)
			for (int b = 2; b <= MAX_B; b++)
			{
				long t = 1 + fMaxTable[d - 1][b] + fMaxTable[d - 1][b - 1];
				
				if (fMaxTable[d - 1][b] == -1 || fMaxTable[d - 1][b - 1] == -1
					|| t > (2L << 32))
					t = -1;
				
				if (b == 2)
					if (t !=  (long)d * ((long)d + 1L) / 2L)
						throw new Error("" + d + " " + b + " " + t + " " + (long)d * ((long)d + 1L) / 2L);
				
				fMaxTable[d][b] = t;
			}

- Marian May 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This problem can be solved in exactly ln(100).
Here is how:
first try from 50th floor -- if it breaks then try 25th floor else try 75th floor
second trying 25th floor -- if breaks then try 12th floor else try 38th floor
...
This was u can get the answer in Log(100) to the base 2.
--KM

- KM June 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Did you even read the problem? You have only 2 bulbs.

I guess the other people here are idiots, who actually bother to read what the problem is.

Also, _exactly_ ln(100)? LOL!

btw, the problem says the bulbs are unbreakable and then says then can break. What gives?

- LOLer June 23, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@LOLer , what are you talking about... you are going to play with balls...oh no...Jesus!!!
How could you think of dropping balls from 100th floor, if by mistake you loose one, then you will remain one baller and if you loose the other one....your done...ball-less...can't just imagine..too much...help these idiots talking all these nonsenes....
Jokes apart, the problem is exactly the same as Egg Dropping problem, find the generalized solution to egg dropping problem for more that 2 eggs, here

http://www.scribd.com/doc/7217370/Egg-Puzzle-Generalized-Solution-for-Any-Number-of-Eggs

- LOLers best friend July 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

14 is possible, but since they only ask max 20 here's an easier way to do it;

i) Drop the first bulb 10 by 10 floors at a time 10, 20, 30... until it breaks
ii) As soon as it breaks go back 9 floors and start going up one by one. So if it breaks in floor 60, you go to 51, 52, 53... until the second breaks

A maximum of 19 is needed in this method

- wilmer August 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

here you have two eggs. How about 1st egg breaks up at 10th floor. Now you are left with 1 egg. How can you test this egg between 1-10 floor?

- test October 01, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

test: If the first egg breaks on the 10th floor, then you start back at the 1st floor with your second egg, drop it and see if it breaks. If it doesn't break, then you drop it from the 2nd floor and see if it breaks. You continue doing this until you get to the 9th floor (assuming it still hasn't broken). If you get to the 9th floor and it doesn't break, you know the answer is the 9th floor since we already determined it breaks on the 10th floor (the answer took 10 drops in this case). If it breaks on the 9th floor, then you know the answer is the 8th floor.

- Me July 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assume the max num of floor is F,

A=int(sqrt(F))
B=int(F/A)

then max time T=A+B-1


example, F=100,
A=10, B=10, T=20-1=19

- huan August 07, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is classic problem in dynamic programming. Use the formula
q(q+1)/2 >=100

q = 14.

Drop the first bulb from floors 14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99, 100... (i.e. move up 14 then 13, then 12 floors, etc) until it breaks (or doesn't at 100).

Binary search will result in 50. Other techniques mentioned above give under 20 which is better than binary search.

- Helper December 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Problem can be solved with derivative methods.

Y = 100/n + n + constant

dY/dn = -200/(n^2) + 1 = 0

And you get n = 14

- X September 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am not sure if i understood correctly..
1. let say we are droping from floor n which is max drop number as well
2. My next floor for drop would be n+n-1 (we have dropped as n so remaing max number of drops are n-1
3. my next floor would be n-2 and so on

So we we sums up all of them then
n+(n-1) + (n-2)+ (n-3)+ ....+1 <=100 (assuming would be final floor)

n(n+1)/2 <=100
or in other words n<=14
Hence worst case n=14

correct me if i am wrong
Ravi

- Anonymous January 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

This is a particularization of the Egg Drop problem (Google CodeJam 2008, Practice Problems) for F = 100 and B = 2

Using the optimal algorithm, the number of drops should not exceed 14.

Here's the code to precalculate the max. allowed F for every D and B:

long[][] fMaxTable = new long[MAX_D + 1][MAX_B + 1];

for (int i = 1; i <= MAX_B; i++)
fMaxTable[1][i] = 1;

for (int i = 1; i <= MAX_D; i++)
fMaxTable[i][1] = i;

for (int d = 2; d <= MAX_D; d++)
for (int b = 2; b <= MAX_B; b++)
{
long t = 1 + fMaxTable[d - 1][b] + fMaxTable[d - 1][b - 1];

if (fMaxTable[d - 1][b] == -1 || fMaxTable[d - 1][b - 1] == -1
|| t > (2L << 32))
t = -1;

if (b == 2)
if (t != (long)d * ((long)d + 1L) / 2L)
throw new Error("" + d + " " + b + " " + t + " " + (long)d * ((long)d + 1L) / 2L);

fMaxTable[d][b] = t;
}

- Marian May 26, 2009 | 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