Bloomberg LP Interview Question for Financial Software Developers






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

I don't think there is any way to find an odd ball with less than 4 tries (for the worst case). I will tell it to the interviewer that in case of 8 balls, we can get it in 3 tries. Which comes to the order of log(n). (cos 2^3 = 8). If you are telling me that there is a way more efficient than log(n) (cos log(9) > 3), then I would love to know that. :-)

- shabs June 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@shabs
champaklal has already described that you can find odd ball in 3 tries.
In summary, divide the ball in 3 sets with 3 balls in each, let it be A, B and C. compare A and B and A and C . This will tell you which set has odd ball and whether that odd ball is heavier or lighter. in third comparison you will find odd ball.

And by the way it is not log(n) base 2. It is log(n) base 3.

- Anonymous June 17, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. divide the balls into 3 ball groups viz A,B,C
2. now weigh A & B. If A=B [in weight] then C is our group. Else,
2a. A & C are to be weighed. the one having unusual weight is picked. This would also tell if one group is heavier or lighter. Suppose C was the group we sought [for the sake of simplicity, we assume whichever is the odd man out is named C].
3. now, if 2 was the case: then weigh two balls from C, if they are equal, then third is our ball. else
3a. measure 3 balls, taking 2 at a time. this will mean 1 more weighing.
4. If 2a was the case, repeat 3 and 3a. but since we know whether the ball is heavy or light, we would not have the confusion. so if one ball is heavy (say) we come to know this is the one, because we had already judged that in 2a.

- champaklal June 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

No. of steps = 3 .

For 9 balls,
Divide them into 3 groups A, B and C of 3 balls each

1) Compare A and B
2) Compare B and C

if A != B and B = C , A contains the ball
if A != B and B!= C , B contains the ball
if A = B and B!= C , C contains the ball

Now we know the set containing the odd ball and are down to just 3 balls

Let the set contain three balls x,y,z .

[ When we used the balance for detecting the odd set, we came to know whether the odd ball is lighter or heavier ]

3) Compare x and y
if x = y , z is the odd ball
if x!= y , depending upon our observation [ lighter or heavier , we find out the odd ball between x and y ]

So , this variation does not have a best or worst case as we have to carry out steps 1 and 2 to determine whether the odd one is lighter or heavier. So in any case , we will require 3 steps

Also, the 8 ball problem requires 2 steps if the odd one is known to be lighter/heavier . Suppose it is heavier

Divide it into a set of 3 balls A = 1,2,3 B = 4,5,6 and C = 7,8

1) Compare A and B . If A = B then goto step 2 . Else goto step 3
2) Compare 7 and 8 and the heavier is the odd one
3) From the heavier set between A and B , compare any 2 balls. If they are equal , third one is odd . Else the one which is heavier is odd.

Thus, 2 steps

- MM2181 June 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Group 9 balls into sets of 3,3 and 3
2. Compare group1 and group2, if both are equal, go to step 4(proceed with group3)
3. Else, Comapare group1 with group3, if they are equal proceed with group2, else with group1
4. Divide balls into 1, 1 and 1
5. Compare ball1 with ball2 once, then with ball3 once.
6. We know the lightest of heaviest ball by now!

- nagabhushana.s July 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

step 4 correction.
- Compare ball1 and ball2
- if ball1 > ball2 => ball1 else ball2
- if ball1 == ball2 then ball3 is heavier

Hence can be done in 2 weighs

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

After reading question again - it seems that we have identify if 9th ball is heavy or lighter that others.
It is possible in 2 weings only.
1. Divide balls in 3 groups A = 4, B =4, C =1
2. Compare A and B if same go to step 3. else go to step 4.
3. Compare any ball from A or B with ball in C. if ball in C is heavy then 9th ball is heavy else lighter. stop.
4. Choose the group which is heavy lets say A is heavy, divide A in to two groups A1=2 and A2=2.
5. if A1 == A2 means all balls is group A are even. and ball in group B is of less weight. else 9th ball is heavy as A was heavier than B. stop

Further, if we have to really identify defective ball we have divide 9 balls into A=3, B=3 and C=3 and this method is already explained above.

- sachin.magdum July 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It can be done in 2 steps
Divide the number of balls into set of 3 - A, B, and C
1) Compare A and B, if A > B move than heavier ball is in set A, else if B > A, than heavier ball is in set B else in set C.
2) Divide the set with heavier ball into 1, 1, 1 each.
3) Repeat step 1 to find heavier ball.

Number of weight reqd = 2.

- Shah July 25, 2015 | 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