Bloomberg LP Interview Question for Financial Software Developers






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

The program is pretty straightforward, i assume we are talking about positive number, for negative numbers you need more clarification from the interviewer. Also number like '2340' will return '432' - this is should be ok.

public static int reverseInteger(int number){
		int num = number;
		int temp;
		int result = 0;
		
		while(num>0){
			temp = num%10;
			num = num/10;
			result = result*10+temp;
		}
		return result;
	}

- Abdul Malik Mansoor February 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

it has traps, you don't take care of overflow and negative numbers

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

@Anonymous: Negative numbers I agree, but can you give an example why an overflow might occur with the above code ?

- Bandicoot March 28, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

An example for char: 129 => 921
the same is possible for int

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

Agree. On 32-bit machine, int range is –2,147,483,648 to 2,147,483,647. If use this number (–2,147,483,648 or 2,147,483,647), it will overflow.

- orangetime23 May 24, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

One solution to prevent overflow: e.g. 2,147,483,647, record digits number d_num before operating last digit (num / 10 == 0), if d_num is 9, then compare with 214,748,364, if less than, do last digit; if equal, compare with 7; if larger than, throw exception.

- orangetime23 May 24, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int reverse( int a)
{
bool negate = false;
if (a < 0)
{
a = a*(-1);
negate = true;
}
num=0;
while(a>0)
{
num = num*10 + a%10;
a= a/10;
}

if(negate)
return num* (-1);
else
return num;
}

- Naren Narayana March 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think in a recursive way you can solve this problem.

public class InverseInteger {
    public static void main(String[] args) {
        int n = 1234;
        System.out.println(inverse(n));
        n = -12345;
        System.out.println(inverse(n));
    }

    private static String inverse(int n) {
        if (n != 0)
            return "" + (n % 10) + inverse((n < 0 ? n * -1 : n) / 10);
        return "";
    }

}

Result:
4321
-54321

- Wilson Cursino March 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int InverseInteger(const int& n){
int temp=n,result=0;
while(temp){
result=result*10+temp%10;
temp/=10;
}
return result;
}
output:
-123456
-654321

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

void reverse(int&);

int main()
{

int x = 12345;
cout << x << endl;
reverse(x);
cout << x << endl;

return 0;
}


void reverse(int &a){
int b = 0;
while(a>0){
b = b*10 + a%10;
a = a /10;
}
a = b;
}

- Jay October 23, 2013 | 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