Bloomberg L.P. Interview Question
803 Interview Reviews |
Back to all Bloomberg L.P. Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Financial Software Developer at Bloomberg L.P.:
Write a java program that can convert a string of numbers (e.g. "5387") into an integer (5387).
See more for this Bloomberg L.P. Financial Software Developer Interview
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (3)
1 of 1 people found this helpful
will this work?
fun() // input 5467
// take first character and transform into integer
//multiply by 10 * index of character which is zero
that is 5 + 0 = 5
then take the next character and transform into integer
now multiply 5 * 10 * index of character which is one
50 +4 = 54
repeat
540+ 6 = 546
5460 + 7 = 5467
running time is O(k) k = no of digits
or O(n) n being the number
Helpful Answer?
Yes |
No
Inappropriate?
For your solution, I understand what you're doing but I think your description of it is a bit off, or at least confusing. The you don't multiply by the index of the character at any time. What you're doing is just multiplying the sum to that point by 10 before adding the next character... i.e. in pseudo code,
sum = 0;
n = (length of the string of characters);
for(i==0; i < n; i++) {
sum *= 10;
sum+= (converted integer value of the character at index i);
}
So the first time through the loop when the index is zero, the initial sum multiplied by 10 is still zero, so you add 5 and get the running sum to be 5. Iteration 2, 5*10 = 50, add the next integer and you get 54, and so on. And that is a far more elegant solution, definitely. Thanks for pointing it out!
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up
0 of 0 people found this helpful
by Interview Candidate: