Bloomberg LP Interview Question for Software Engineer / Developers






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

Use an integer array of size 255. For each character occurrence increase the corresponding count and compare the new count to current global maximum.

- Anon November 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
3
of 3 vote

Hi, This is the efficient code in C++ for finding out first most populas character.

char findFirstMostPopulas (char *strPtr)
{
int freq[256] = { 0 };
char *charPtr = strPtr;

while ( *charPtr != '\0')
{
freq[*charPtr]++;
charPtr++;
}
charPtr = strPtr;
char* mostPopulas = charPtr;
while ( *charPtr != '\0' )
{
if (freq[*mostPopulas] < freq[*charPtr])
mostPopulas = charPtr;
charPtr++;
}

return *mostPopulas;
}

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

hash the charactes

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

hash the characters

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

By populous do you mean the one that repeats the most in a string?

- sergevanwarez November 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, character that occurs most.

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

use segment trees

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

Hash Table is the best option ... iterate once over the character of the string, and have a counter to fetch the previous value and increment and insert it again.

//The second solution like Integer arr[255] would fail in case of other characters like åß∂ƒ©˙∆˚¬Ω≈ç∫˜¡™£¢∞¶•ªº

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

ya but you would have to compute the hash function every-time you come across a new char and insertion and deletion does take a constant amount of time so it would be better to use an array which holds the number of occurrences of every char in the string to there respective position in the string correspondingly in the array to.

- deric January 16, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>

#define N 256

int findMostPopChar(char *s){
int ht[N];
int maxCnt = 0;
int maxInd = -1;
int i;

for(i = 0 ; i < N; i++){
ht[i] = 0;
}

while(*s++){
/* assert to make sure *s is in [0,255] range */
ht[*s]++;

if(ht[*s] > maxCnt){
maxCnt = ht[*s];
maxInd = *s;
}
}
return maxInd;
}

int main(){

char *s = "abjdjdjdjakjdkdjdkjdjdjdjdjkdjkd ";
printf("most pop. char = %c\n", findMostPopChar(s));
return 0;
}

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

That's one buggy piece of software. A good question would be - how many inefficiencies and style improvements can you suggest? And can you find the bug?
------
Hint : that's why we don't write stuff like
"while(*s++)" at Bloomberg. It's hard to read and bug-prone.

- bloombergoid September 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

string str("abcdeabcdefghikjaa");

int len = str.length();

int location, maxcount;
char ch;
int noftimes;

location = maxcount = noftimes = 0;
for (int i = 0 ; i < len ; i++)
{
ch = str[i];
noftimes = 0;
for(int j = i+1; j< len ; j++)
{
if(ch == str[j])
{
noftimes++;
}
}

if (noftimes > maxcount )
{
maxcount = noftimes;
location = i;
}
}

return str[location];
}


complexity is o(n2);

- Anonymous January 06, 2012 | 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