Microsoft Interview Question for Software Engineer in Tests






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

Reverse the whole string first char by char. Then reverse the chars of individual words.
I wonder if there is a much smarter way of doing the same ! there should be.

Both the steps are orthogonal, so order doesn't matter.

- knap October 15, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
void rev(char *r,char *l)
{
char temp;
while(r<l)
{
temp=*r;
*r=*l;
*l=temp;
r++;
l--;
}
}
void revword(char *str)
{
char *end,*x,*y,i;
for(end=str;*end;end++);
//reverse complete sentence
rev(str,end-1);
//reverse word in the sentence
x=y=str;
while(x++<end)
{
if(*x==' '||*x=='\0')
{
rev(y,x-1);
y=x+1;
}
}
}
main()
{
char s[]="my name is anthony";
revword(s);
printf("\nafter rev : %s",s);
return 0;
}

- rajnesh November 08, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good.

- XYZ November 21, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void revString(char * str){

int i = 0;
if (str == null) {
return (char *)0;
} else {
while ( *(str+i) != '\0'){
if (*(str+i) == ' ' || *(str+i) == '\t'){
i++;
} else {
int start = i;

while (*(str+i+j) )

}
}
}


}

- Anonymous November 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let me complete your code

void revString(char * str){

  int i = 0;
  int start = 0, j =0;
  char temp;
  if (str == null) {
    return (char *)0;
  } else {
    while ( *(str+i) != '\0'){
    if (*(str+i) == ' ' || *(str+i) == '\t'){
    i++;
  } else {
    start = i;
    j = 0;
    while (*(str+i+j) != '\0' || *(str+i+j) != ' ' )
         j++; 
    
    int k = 0;
    while ( k < j - 1 ){
       temp = *(str + start + k);
       *(str + start + k) = *(str + start + j - 1 - k);
       *(str + start + j -1 - k) = temp;
    }    
 
   i =  start + j ;
   }
 }
 }

}

- Anonymous November 23, 2009 | 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