Bloomberg LP Interview Question for Financial Software Developers






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

Hardcode an array of 128 bools to represent Ascii chars. bool a[128]
Set each location to false a[0] = false ....
This represents characters that are not to be removed
Fill in other locations with chars to remove ie 'A' a[69] = true

std::string newstr;
for ( int i=0; i<origstr.Length; i++ )
if ( a[origstr[i]] == false ) newstr += a[origstr[i] );

O(n+128) = O(n);

- WCampbell September 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Whatever you do, you will need to traverse two strings, so solution cannot be less than O(n)+O(m).

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

Hrm; but O(n) + O(m) /is/ sort of O(n) (assuming similar-length strings, O(2n) == O(n)).

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

Yep, JeffD is right. O(m+n) = O(n) if n>m else O(m) if m>n.
if the interviewer exactly means in n comparisons irrespective of the other string's length then I would give him a parallel programming approach which is possible to have O(1) or O(k) k<<n complexity depending on length of strings.

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

you can't do it without go through the str2, so O(n+m) is the correct answer. may be he means space complexity in O(n)

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

exactly we cant do it without goin thru the string2..
min time complexity can be O(n)+O(m) i.e as u map string2 in a hash table ...

- saumil August 25, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bit map for str1 chars

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

Use suffix trees to preprocess. Construction of suffix trees can be done in O(n) and then searching depends on what pattern you want to search.

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

I dont think building a suffix tree is a good solution as you need to identify all the characters in str2 that occur in str1. the characters of str2 can be spread out in str1
eg:
str1= "monkeydonkey" str2="okden"
Suffix tree can be used to find out the occurance of sub string str2 within str1
I am thinking more like finding the longest common subsequence.
Its a dynamic programming problem

- div January 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if they are sorted, we can do it in O(n)

- Anonymous April 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Can we do something like this:

let str1 = "hello world" and str2="wo1". Now he wants us to remove all characters in str1 that occur in str2. so we remove the characters "w" and "o" from str1. we dont remove "1" since it doesnt occur in str1.

char* ptr1 = &str1[0] and char * ptr2 = &str2[0];

so, while(*ptr1 && *ptr2)
{
if(*ptr2 == *ptr1) {
delete from str1 the character pointed by ptr1;
ptr2++;
}

ptr1++;

if(ptr1 == NULL || ptr2 == NULL)
break;
}

this is O(n).. or am i missing something here?

- Jester January 21, 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