Bloomberg LP Interview Question for Software Engineer Interns


Country: United States
Interview Type: Phone Interview




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

int my_strcmp ( char *s, char *t ) {

	while ( *s == *t ) {
		if (*s == '\0')
			return 0 ;
		s++ ;
		t++ ;
	}

	return (*s - *t) ;
}

- R@M3$H.N December 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I'll change argument types to const char* and use prefix increment instead of postfix.

- paruyrkh January 05, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

int strcmp(char *a,char *b)
{
int cmp =-1;
While (*a == *b && *a!='\0' && *b!='\0')
{
	a++;b++;
	cmp=0;
}
if(*a=='\0' && *b=='\0' && cmp==0)
{
	cmp= 0;
}
else if(*a<*b)
	cmp= -1;
else
	cmp= 1;
	
return cmp;
}

- gargayushi19 December 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Lot of unnecessary code. For example, you test

if (... && cmp == 0) {
    cmp = 0;
}

Why assign 0 to cmp if it is already 0?

- paruyrkh January 05, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int mystrcmp(char *a, char *b)
{
	int m=strlen(a), n=strlen(b);
	if (m==0 && n==0)
		return 0;
	if (m==0)
		return -1;
	if (n==0)
		return 1;
	return mystrcmp(++a,++b);
}

- ts December 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Let's suppose two string have 5 chars. This implies that m != 0 && n != 0 so your code will recursively call itself for last 4 chars ignoring first chars. So, it is not correct - you never compare symbols and are only looking into lengths of strings

- paruyrkh January 05, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int cmp(char *,char *);
int main()
{
char s[100],s1[100];
int d;
gets(s);
gets(s1);
d=cmp(s,s1);
if(d==1)
printf("equal");
else
printf("not equal");
}
int cmp(char *a,char *b)
{
int c;
while(*a!='\0'||*b!='\0')
{
if(*a==*b)
c=1;
else
{
c=0;
break;
}
*a++;
*b++;
}
return c;
}

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

package career.cup.bloomberg;

public class stringCmp {
	
	public static void main(String args[]) {
		System.out.println("String Compare "+strLocalCmp("Hello","Hello"));
	}

	private static boolean strLocalCmp(String string, String string2) {
		// TODO Auto-generated method stub
		
		if(string==null || string2 == null){
			return false;
		}
		
		if(string.length() != string2.length()) {
			return false;
		}
		
		for(int i=0;i<string.length();i++){
			if(string.charAt(i) != string2.charAt(i)) {
				return false;
			}
		}
		
		return true;
	}

}

- hm January 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int my_strcmp(char* s1, char* s2)
{
	while(*s1!='\0' && *s2!='\0')
	{
		if(*s1>*s2)
			return 1;
		else if(*s1<*s2)
			return -1;
			
		s1++;
		s2++;
	}
	
	return *s1=='\0'&&*s2=='\0'?true:*s1=='\0'?-1:1;
}



int main() {
	cout<<my_strcmp("abc","ab");
	return 0;
}

- naomi.lijing@googlemail.com February 25, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I see a lot of code with the potential to dereference NULL pointers, which is undefined behavior.

- sk3l April 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry. Please ignore my previous comment. I could not delete it.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int mystrcmp(char *a, char *b) {
	if (a && b) {
		while (*a == *b) {
			if (*a == '\0' || *b == '\0') {
				return 0;
			}
			a++;
			b++;
		}
		return(*a - *b > 0 ? 1:-1);
	}
	else {
		return 0;
	}
}

void assertInt(int a, int b) {
	if (a == b) {
		printf("Passed\n");
	}
	else {
		printf("Failed\n");
	}
}
int main() {
	char * a = "abc";
	char * b = "def";
	assertInt(strcmp(a, b), mystrcmp(a, b));
	assertInt(strcmp("bcde", "bcde"), mystrcmp("bcde", "bcde"));
	assertInt(strcmp("", "bcde"), mystrcmp("", "bcde"));
	assertInt(strcmp("", ""), mystrcmp("", ""));
	assertInt(strcmp("gde", ""), mystrcmp("gde", ""));
}

- snugkim June 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<stdio.h>
#include<stdlib.h>

int main()
{
char *a = "this is good";
char *b = "this is good";
int cmp;

while(*a == *b && *a != '\0' && *b != '\0')
{
        cmp = 0;
        a++;
        b++;
}
if(*a == '\0' && *b == '\0' && cmp ==0)
{
        printf("equal\n");
}
else
{
        printf("not equal\n");
}

}

- kshitiz gupta December 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why you wrote the stdlib.h

- yagnik December 19, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

What you tried to implement? Is it strcmp? cmp variable is not initialized and you may end up using uninitialized variable

- paruyrkh January 05, 2015 | 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