Microsoft Interview Question for Software Engineer in Tests






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

This seems to be a very common question - to reverse a string
I'd give strings of size 0,1,2,3, and some very large length string, and NULL for testing. To reverse, use 2 pointers one moving from left to right and the other from right to left, and keep swapping the contents pointed by them. Do this while the distance between them <= 1.

- acoader November 05, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a really good one acoader :)

- Cheema May 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char *strrev(const char *str){

  char *revstr = (char *)malloc(strlen(char)+1);
  int i = 0;
  while ( i < strlen(str) ) {
    *(revstr + i) = *(str + strlen(str) - i - 1);
    i++;
  }
  *(revstr + i ) = '\0';

return revstr;  
}

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

void reverse(char *s)
{
char *t = s;
while(*t) t++;
t--;
char *temp;
while(s<t)
{
temp = *s
*s++ = *t;
*t--=temp;
}

}

- optimized sol November 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

# Program:

def reversal(string):

  if string is None:
    return string

  if len(string) == 1 or 0:
    return string
  
  string = string.encode('utf-8')

  string = list(string)
  i = 0 
  j = len(string) - 1
  
  while i <= j:
    string[i], string[j] = string[j], string[i]
    i += 1
    j -= 1

  return ''.join(string)

print reversal('ab csdjkf,!wiuro ')

# Test cases:

a) Single character string
b) Empty string
c) Null string
d) Unicode character string
e) Lengthy string (50 MB)
f) String with spaces, punctuations, exclamation, period, etc,.

- Galileo December 02, 2014 | 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