Bloomberg LP Interview Question for Financial Software Developers






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

given a string, a = "a cd ef ed ca"
pivot1 points to starting of string, pivot2 points to end of string

while(pivot1<=pivot2)
  if(a[pivot1]!=' ' and a[pivot2]!=' ')
     if(a[pivot1]==a[pivot2])
         ++pivot1,--pivot2, continue loop
     else
         "Not a palindrome", palindromeflag = false, break;
  else if(a[pivot1]==' ')
     increment pivot1 and continue loop
  else if(a[pivot2]==' ')
     decrement pivot2 and continue loop

- chennavarri October 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include <iostream>
#include <string.h>
using namespace std;
int main(){
	char a[] = "a cd ef   ed ca";
	bool palindromeflag  = true;
	int pivot1=0,pivot2=sizeof(a)-2;
	while(pivot1<=pivot2){
		if(a[pivot1]!=' ' and a[pivot2]!=' '){
			if(a[pivot1]==a[pivot2]){
				++pivot1;--pivot2; continue;
			}else{
				palindromeflag = false;break;
			}
		}else if(a[pivot1]==' '){
			++pivot1; continue;
		}else if(a[pivot2]==' '){
			--pivot2; continue;
		}
	}
	if(palindromeflag)
		cout<<"Palindrome"<<endl;
	else
		cout<<"Not a palindrome"<<endl;
}

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

that's easy man

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

Will tis work???

- Roohitha Kabarkhan October 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

why cant we just push all characters onto a stack except spaces and pop out and check if they are the same characters...

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

Conceptually, there's nothing wrong doing it using a stack. However, is that the best we can do in terms of time and space? It is clear that in terms of space using stack isn't efficient than blueskin's and chennavarri's solutions, as we will need to construct a stack.

How about computational efficiency? How many comparisons are needed? If you use stack you will need n comparisons, where n is length of the string, as you will be comparing two different strings. On the other hand blueskin's and chennavarri's solutions take n/2 comparisons.

It's now very clear (at least to me) that stack based solution is probably not the most efficient.

- rayhan August 12, 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