Morgan Stanley Interview Question for Analysts


Team: Morgan Stanley
Country: India
Interview Type: In-Person




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

It seems they asked for in-place reversal. So.

char * strRev(char *s)
{
char *p,*q;
p=q=s;
while(*q!='\0') q++;
q--;
while(p<q)
{
*p=*p+*q; //Swapping Characters
*q=*p-*q;
*p=*p-*q;
}
return s;
}

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

char * strRev(char *s)
{
char *p,*q;
p=q=s;
while(*q!='\0') q++;
q--;
while(p<q)
{
*p=*p+*q; //Swapping Characters
*q=*p-*q;
*p=*p-*q;
p++;
q--

}
return s;
}

- prashanth September 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yup. Forgot that part. Thanks for adding.

- amitlangote09 September 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This will crash if 's' is NULL

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

#include<stdio.h>
#include<string.h>

char* StrReverse(char* str)
{
char *temp, *ptr;
int len, i;

temp=str;
for(len=0; *temp !='\0';temp++, len++);

ptr=malloc(sizeof(char)*(len+1));

for(i=len-1; i>=0; i--)
*(ptr+len-i-1)=*(str+i);

*(ptr+len)='\0';
return ptr;
}


int main()
{
char string;
printf("enter the string to be reversed \n");
scanf("%s",string);
strReverse(string);
printf("the reversed string is %s",string);
}

- prashanthi.07 September 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<string.h>

char* StrReverse(char* str)
{
char *temp, *ptr;
int len, i;

temp=str;
for(len=0; *temp !='\0';temp++, len++);

ptr=malloc(sizeof(char)*(len+1));

for(i=len-1; i>=0; i--)
*(ptr+len-i-1)=*(str+i);

*(ptr+len)='\0';
return ptr;
}

int main()
{
char string;
printf("enter the string to be reversed \n");
scanf("%s",string);
rev = strReverse(string);
printf("the reversed string is %s",rev);
}

- prashanthi.07 September 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Extra storage space is used in your code, seems don't meet the requirement of the question.

- liufengdip June 25, 2012 | 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