Bloomberg LP Interview Question for Software Engineer / Developers






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

ADD(p,q)
{
if(p==0)
return r;
else
int k,r;
k=p^q;
r=p&q;

ADD(k,r<<1);
}

- Anonymous February 27, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice! just a few typos:

with unit test:

#include <iostream>
int add(int p, int q)
{
if(q == 0)
return p;
int k, r;
k = p ^ q;
r = p & q;
return add(k, r<<1);
}
int main() {
printf("%d\n", add(4,7));
printf("%d\n", add(401,7));
printf("%d\n", add(14,7));
printf("%d\n", add(4,47));
printf("%d\n", add(4,-97));
}

- redroof November 05, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

you missed the situation when q is initially 0

- Anonymous September 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 0 vote

I think we can do this as follows:

int main(){
int a = 9, b = 10;
char *p;
p = (char*)a;
int sum = (int)&(p[b])
cout<<sum;
}

- SID November 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can make use of binary operations
for example
4 -> 0100
2 -> 0010
making an OR operation will give 0110 -> 6

so int p=4;
int q=2;
int r=p||q; will give 6

- ked February 26, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Use XOR instead of OR operator.

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

This is wrong. Take p=3, q=1 as an example. Also the logic or is | but not ||.

With loop.

for (int i=0; i<p; i++)
q++;

without loop.

int p,q;
add(p);

add(int val)
{
if (val==0)
return;
p++;
add(val-1);
}

- Lindos February 26, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

p++? i think this one uses the + operator

you should OR it with 1

- turt March 19, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is correct solution as Initially I also didnot think of ++ operator because internally it uses + operator. But the interviewer was expecting me to use ++ operator. So, please don't go in AND & OR operations. With loop use ++ operator without loop use recursion.

- Gaurav April 17, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

the ques doesnt say that we cant use the - operator
so c = 0-b;
sum = a-c;

does this qualify or not

- "-" operator March 03, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

'-' operation is implemented using addition & 2's complement

- Anonymous November 17, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

best solution!

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

niceee !!

- Anonymous March 04, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a-(-b)

- zdmytriv March 06, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if a>b then
sum = a - remainder (a/b)
else
sum = b - remainder (b/a)

- Kapil March 08, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

{sum=a^b^(a&b)}

- Anonymous March 09, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

wrong!!!! try for 300 + 55 ...gives 319 :(

- Anonymous September 18, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

hmmm.. Just do this..

-1 * (-1*a - b)

- zhandu March 11, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

given a, b are two numbers
do

(a+b) * (a-b) = pow(a, 2) - pow(b,2)

so

a+b = (pow(a, 2) - pow(b,2))/ (a-b)

use this

- Anonymous July 24, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ln(exp(a)*exp(b))

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

in case u dun get it lg(exp(a)*exp(b)) = lg(exp(a+b)) = a+b

- wihenao August 24, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

a + b without using + operator:

solution = ~(a AND b)

- zorba December 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wrong Answer:

By ur logic 0+0 = 15

- Gaurav June 08, 2010 | Flag
Comment hidden because of low score. Click to expand.
-1
of 0 vote

Sum = A XOR B
Carry = A AND B

- Aditya October 26, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

is this a half adder..i think we need a full adder instead ..or something for N bits like a Ripple carry adder or Carry look-ahead adders

- sk April 17, 2009 | Flag


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