Bloomberg LP Interview Question for Financial Software Developers






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

I think first reverse the string as "ogacihC morf ma I"
Now reverse each word to get "chicago from am I"

- ekapil2 October 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

I would suggest reversing the string as a solution given below:
"I am from Chicago"
Step 1: Read the characters from rear and keep it infront of the String
"o I am from Chicag"
"go I am from Chica"
and soon until
"Chicago I am from "
Step 2: Now reads the space. In this case, locate the position of first " " [space] from Chicago. Now follow the same process as given above in step 1
"Chicago m I am fro"
"Chicago om I am fr"
"Chicago rom I am f"
"Chicago from I am "
Now again space came at rear. Now go to the first space after from and follow the first step.

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

public static void revOneByte(char arr[]){
int len = arr.length;
char temp;
int l=0;
int t;
while(l<len-1)
{
t=l;
while(arr[len-1]!=' ')
{
temp = arr[len-1];
System.arraycopy(arr,t,arr,t+1,len-(t+1));
arr[t] = temp;
l++;
}
System.arraycopy(arr,l,arr,l+1,len-(l+1));
arr[l]= ' ';
l++;
}

System.out.println(arr);
}

- garvit November 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

can u give the code pls

- praneeth October 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can u give the code pls

- praneeth October 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

quick question, using int's for looping over or recursive functions for referring to index is allowed or not??

- chennavarri October 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let me elaborate on what ekapil2 said .
First make a function reverse(char *a,int start,int end)which reverses an array given its start and end .
Second reverse the entire array .
Third make a function that reverses words i.e. it checks for spaces b/w words and asks reverse() to reverse it by sending its start and end .

- Ankur October 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Stack is the Best Data Structure for this. Store each word as a string and get the items back in the reverse order from stack.

- sp October 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How can stack be used in this case? Its already mentioned that you have 1 byte of memory. I guess reversing idea will work. However, we will require some extra memory to keep track when reversing each words...

- PK October 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The first & simplest I can think of is:
Use the temporary byte and do shift right by the size of the array times.
Steps:
eg: "I AM NSK"

0. Given Array: "I AM NSK" Byte: ' '
i. " I AM NS" 'K' (push last char K to the tmp byte.
ii. "KI AM NS" ' ' (push from tmp byte to first byte of Array).
iii." KI AM N" 'S'; "SKI AM N" ' '
iv. " SKI AM " 'N'; "NSKI AM "
v. do this by n time where n is the length of the array. And We have what we wanted.

As you know, first thought is always unamortized, there may be better solutions.
Best storage for this linked list of words where reversing is cheaper(concept of stack or use two pivots).

- NSK October 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

!!! This is wrong. Ignore the above approach !!!

- NSK October 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You realized it pretty quickly dint u! :P

- Shrey February 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void chicago(char str[], int,int len);
void chicagoRev(){

	char str[] = {"I am from Chicago"};
	int len = strlen(str);
	chicago(str, 0, len);
	int j = 0;
	for(int i=0;i< len-1; i++){
		
		if(str[i] == ' '){
			chicago(str, j,i);
			j = i+1;
		}
	}
	cout << str;
}

void chicago(char str[], int start,int len) {
for(int i=start, j=len-1; i< ((start+len)/2), j>=(start+len)/2; i++, j--)
	{
		char temp = str[i];
		str[i] = str[j];
		str[j] = temp;
	}
}

I hope this is the solution.

- Richa Aggarwal November 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This code works! However there could be one improvement: if there are multiple blank spaces laying in the middle, say " I am from Chicago". you will make unnecessary calls to chicago().

- AW November 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i'm not sure if those two integers "len" and "j" count as "temporary variable". Because it mentioned we can only use a char ....

- mtndew February 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Surely, since one byte of memory allows to swap two characters, we can recombine them in any way. I guess, besides the kind of code Richa wrote above, the answer would be that a linked list of characters would easily allow to relink the words as required.

- igorfact July 11, 2014 | 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