Bloomberg LP Interview Question for Software Engineer / Developers






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

Find all prime numbers in [1,999999999], and put these numbers in a set. Look up xxx,xx,xxxx and xxx-xx-xxxx in this set. Before that, a preprocessing is needed to get the integer number of xxx,xx,xxxx and xxx-xx-xxxx. For example, The xxx could be 010, so the real number is 10.

To find all prime numbers between [7,n]:
int prime[] = {1,3,5};
int total = 3;
int gap = 2;
for(i = 7; i <= n; i+=gap){
gap = 6-gap;
int j = 1;
bool flag = true;
while(prime[j]^2 < i){
if (i%prime[j] == 0){
flag = false;
break;
}
}
if(flag == true){
prime[total++] = i;
}
}

- Xiao January 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What you mean by ^?

- Padmanabha Reddy Kolagatla February 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

We only need to look up n/(6*3) numbers between [7,n] to find all prime numbers

- Xiao January 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Good algo Xiao, but won't it be enough to find all prime between [100.00.0000 - 999.99.9999] and then find out all 3, 2 and 4 digit primes using you algorithm.

- Sharat January 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You are not required to generate a 9 digit prime. You only want to verify if it is a prime. So, generating a list of all primes is unnecessary here.

Generate a random 9 digit number. Split it into xx, xxx, xxxx and xxx-xx-xxxx. Pass these four numbers to the function that verifies if a number is prime or not. AND the result of the four method calls return the result.

To test if a number n is prime, divide n with [1, sqrt(n)] and if any one produces a remainder of 0, the number is not prime.

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

It is faster to generate prime number list because the amount of prime numbers is small. Then you can find if the input SSN is a prime or not fast. It is waste of time to call the function each time.

- Xiao February 10, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

how to generate a 9 digits random number?
RAND_MAX varies between compilers and can be as low as 32767

randomly generate 4 digits 2 digits 3 digits then put them together?

any other solutions?

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

skip it

with my ubuntu, g++; RAND_MAX eq 2147483647

- Anonymous February 25, 2010 | 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