Bloomberg LP Interview Question for Software Engineer / Developers






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

void sort(char* a, int l)
{
int t = 0;
for (p = 0; p < l; p++)
{
if (a[p] == 'R' && p != t)
{
a[p] = a[t];
a[t++] = 'R';
}
}
}

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

use counting sorting,

count the number of R's and B's and place number's of R's and then the numbers of B.

sorting not needed. complexity O(n).

- puru July 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Puru is guru!
Superb

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

Even without counting sort this can be done in O(n) time


Ri = Size-1
Bi = 0
while (Bi > Ri && Bi < Size-1 && Ri >0 )
{
while (Array[Bi] == Red) Bi++;
while (Array[Ri]) == Blue) Ri--;
else if (Bi > Ri)
{swap (Array[Bi],Array[Ri]);}
}


this is essentially partition routine of quicksort.
though it has two level of looping essentially it is O(n) as the iteration of indeices is once

- Amit Priyadarshi July 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

there are couple of errrors..
* Bi=0 > Ri? It doesnt even enter first while loop
* sec and third while has to be if
* conditions r wrong in while loops

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

Amit's logic can be generalized, for R,G,B... and so on. by using Array of place pointer.
In the above example and Bi and Ri are used as place pointers, same way. We are using two pointer because we know we have two type of objects.
Later on if number of R,G,B... are numerious, then searchin in array will require hashing.

for (int i=0; i<n; i++)
{
hash[arr[i]] ++;
}

- sachin.magdum July 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this is a common CS problem known as "Dutch National Flag" Problem.

- AD August 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

agreed

- Anonymous October 31, 2011 | 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