Bloomberg LP Interview Question
Financial Software Developersbreak it into 2,2,3
1. balance 2 and 2.
if 2=2 then goto "For 3 coins";
if 2=!2 then goto "For 4 coins";
For 3 coins:
2. balance A and B.
if A=B, then return C.
if A=!B, then do step 2.
3. balance A and C.
if A=C, return B.
if A=!C, return C.
For 4 coins:
2.Balance A and B. 3.Balance A and C.
if A=B
if A=C, then return D.
if A=!C, then return C.
if A=!B
if A=c, then return B.
if A=!c, then return A
break it into 2,2,3
1. balance 2 and 2.
if 2=2 then goto "For 3 coins";
if 2=!2 then goto "For 4 coins";
For 3 coins:
2. balance A and B.
if A=B, then return C.
if A=!B, then do step 3.
3. balance A and C.
if A=C, return B.
if A=!C, return C.
For 4 coins:
2.Balance A and B. 3.Balance A and C.
if A=B
----if A=C, then return D.
----if A=!C, then return C.
if A=!B
----if A=c, then return B.
----if A=!c, then return A
#1.break the coins into 3,3 and 1
- Tejaswi February 03, 2011#2. balance 3 and 3 (if they are equal weight then the single coin you didnt balance is the heavier coin)
else
#3. take the the side of the balance which is heavier and break it again in 1,1 and 1(discard the lighter side coins and the remaining one coin)
#4. balance again 1 and 1 each, if they are equal then the one you are holding is heavier or the one which is showing on the balance as heavier is heavier