Bloomberg LP Interview Question for Financial Software Developers






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

I assume by reverse, you mean the following:
123=>321
-123=>-321
+123=>+321

If the input is 'string', you might need some string manipulation.
Trim any extra spaces,commas etc.
Parse the leftmost char, if it's +/-, preserve it some stack.
Then try the following algo.
newnum=0;
while(num)
{
i=num%10;
if(newnum==0)
{
newnum=i;
}
else
{
newnum=newnum*10+i;
}
num=num/10;
}
return newnum;

- B January 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can any one pls exp what is "reverse"

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

also, what is -ve and +ve?

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

hey wat if i take num=0321. Then it shud convert it to 1230.
i tried my code but it is not converting the number to 1230.
and same problem i found with ur code.

- creativites January 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you take an integer like 0321? Does it make sense?

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

yeah.. true . But i have problem like if you reverse a number 2 times then we should get the same number.

But problem comes in case like this:
number=1230 reversed into =>0321 and if u reverse it again then we should get number=>1230.

- creativites January 02, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i agree with colab. but there is no way to store 0321 as an int. Instead you are expecting the function argument is a string, which can store "0321". And it would be easy to reverse the string.

- kyra January 15, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You are correct, any integer reversed twice should be equal to its original value. The reason you are experiencing all these problems is because you are reversing characters of a corresponding string representation of an integer, instead of reversing bits of that integer. If you look at binary representation of 2 (00000010) and truly reverse it to 01000000, you will arrive to decimal 64. Then, if you reverse 64 (01000000) back to 00000010, you will have your decimal 2 back.

- cplusplus January 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

why not simply convert the integer to string and reverse the string and then convert the string to integer. :0

- Anonymous January 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int reverseDigits(int digit)
{
	int isNegative = 0;
	if(digit<0) {
		isNegative =1;
		digit*=-1;
	}
	if(digit==0) return 0;

	int reverse=0;
	while(digit){
		reverse*=10;
		reverse += digit%10;		
		digit/=10;		
	}	
	return isNegative==0? reverse:reverse*-1;
	
}

- Karthik January 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What if I input a number, whose reverse will go out of range for int? That is the catch in this questions.

Say, I used short in place of int. Then a number like 23289 when reversed will go out of range of short.

- Mahesh February 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int reverse=0;
while(digit>0){

then it will work

- Anonymous January 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this:

Let N = 2350.

while(N)
{
int x = N%10;
push(S, x); //push x into a stack S.
N /= 10;
k++ ; //keeps track of length of N
}

//now do pop operation
while(k--)
{
printf( "%d", pop(S));
}

- cirus February 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

why to use separate counter k ??? just calculate length of N using in-built function len(n). It will return the length and this or similar function is available in all languages.

- ;) February 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

+ve and -ve are abbreviations for “positive” and “negative”.

- stachenov October 19, 2016 | 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