Microsoft Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

void revString(String s)
{

for(int i=0;i<len/2;i++) //len- stands for string length;
{

s[i]=s[i]+s[len-i];
s[len-i]=s[i]-s[len-i];
s[i]=s[i]-s[len-i];

}

}

- Manish May 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Here is the C code.

#include <stdio.h>
void 
main()
{
char s[] = "abcd";
char temp;
int len_s = strlen(s);

	for (int i=0;i<len_s/2;i++)
	{
		temp = s[i];
		s[i] = s[len_s - i - 1];
		s[len_s - i -1] = temp;
	}
	printf ("%s\n", s);
}

And Here is the C++ Code.

#include <atlstr.h>
void 
main()
{
	CString s(_T("abcd"));
	s.MakeReverse ();
}

- viprsshr May 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

private static char[] reverseString_in_Char_Array(String string) {
char[] str = string.toCharArray();
boolean isPalindrom = true;
int j = str.length - 1;
for (int i = 0; i < (str.length) / 2; i++) {
if (str[i] == str[j]) {
j--;
continue;
} else {
isPalindrom = false;
char temp = str[i];
str[i] = str[j];
str[j] = temp;
j--;
}
}
System.out.println("Palindrom" + isPalindrom);
return str;
}

/**
* 1
*
* @param str
* @return
*/
private static StringBuilder reverseString(String str) {
StringBuilder sb = new StringBuilder();
for (int i = str.length() - 1; i >= 0; i--) {
sb = sb.append(str.charAt(i));
}
return sb;
}

- sylvia.laurel.oak September 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Java:

StringBuffer s = new StringBuffer("hello");
System.out.println(s.reverse());

- rajarshi129 October 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Python : ---

1.

s = 'INPUT_STRING'
chars = list(s)
reverse = ''.join(chars.reverse())

-------
2.
chars = list(s)
for i in range(len(chars)/2):
chars[i], chars[-1*(i+1)] = chars[-1*(i+1)], chars[i]

- virgo676 May 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String reverse(String input) {
if(input == null)
return input;
if(input.length() <= 1)
return input;

return DIYString.reverse(input.substring(1)) + input.charAt(0);
}

- Anonymous May 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void reverse(char input[], int len)
{
char* start = input;
char* end = input + len;

while (start < end)
{
char temp = *start;
*start = *end;
*end = temp;
++start;
--end;
}
}

- bugbug May 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

basicalgos.blogspot.com/2012/03/4.html

- Andy May 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It's difficult for me to believe that MS is asking such simple questions in f2f interviews. Can someone please comment on difficulty of MS in-person interviews?

- Curious May 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

s='test string'
print s[::-1]

- feisky May 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Python

s='test string'
print s[::-1]

- feisky May 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

strrev('String');

}

- Manish May 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void reverse(char *input, int size)
{
for(int i = 0;i<size/2;i++)
{
char temp;
temp = *(input+i);
*(input+i) = *(input+len-i-1);
*(input+len-i-1) = temp;
}
}

- Pradeep May 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char *reverse(char *s, int n)
{
//n is strlen here
if (n<=1) return s;
return (strconcat(reverse(substring(s,1,n-1), n-1),substring(s,0,0),1);
}

- Anonymous May 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char *reverse(char *s, int n)
{
//n is strlen here
if (n<=1) return s;
return (strconcat(reverse(substring(s,1,n-1), n-1),substring(s,0,0),1);
}

- Anonymous May 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char *reverse(char *s, int n)
{
//n is strlen here
if (n<=1) return s;
return (strconcat(reverse(substring(s,1,n-1), n-1),substring(s,0,0),1);
}

- Ashish May 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Java
class StringReverse
{
public static void main(String... args)
{
Scanner scan=new Scanner(System.in);
System.out.println("enter a string");
str=scan.next();
StringBuffer sb=new StringBuffer(str);
sb.reverse();//a method in StringBuffer to reverse a string
System.out.println(sb);
}}

- balaji May 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void reverseEntireString(char[] input){
if(input==null || input.length<=1)return;
for(int i=0;i<input.length/2;i++){
input[i]=(char) (input[input.length-1-i]^input[i]);
input[input.length-1-i]=(char) (input[input.length-1-i]^input[i]);
input[i]=(char) (input[input.length-1-i]^input[i]);
}
}

- Test May 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

"String".reverse

- Khalid May 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ruby

"String".reverse

- Khalid May 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ruby

"String".reverse

- Khalid May 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

C#
====

string reverseString(string text)
{
char[] arr = text.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}

- Siva May 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I bet here they want to see the recursive algorithm (that is the most interesting).

reverse(char* s)
{
if (*s)
reverse(s+1);
printf("%c",s);
}

void main()
{
char* s="abcd";
reverse(s);
}

- BBB June 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char* reverse(char* str)
{
if(str)
{
size_t end = strlen(str) - 1;
size_t start = 0;

while(start < end)
{
str[start] ^= str[end];
str[end] ^= str[start];
str[start] ^= str[end];

start++;
end--;
}
}

return str;
}

- chris June 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why cannot we use stack and pop out.

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

Because that would result in unnecessary space wastage.

- teli.vaibhav June 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

static class StringHelper
{
    /// <summary>
    /// Receives string and returns the string with its letters reversed.
    /// </summary>
    public static string ReverseString(string s)
    {
	char[] arr = s.ToCharArray();
	Array.Reverse(arr);
	return new string(arr);
    }
}

class Program
{
    static void Main()
    {
	Console.WriteLine(StringHelper.ReverseString("framework"));
	Console.WriteLine(StringHelper.ReverseString("samuel"));
	Console.WriteLine(StringHelper.ReverseString("example string"));
    }

- King October 24, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static class StringHelper
{
    /// <summary>
    /// Receives string and returns the string with its letters reversed.
    /// </summary>
    public static string ReverseString(string s)
    {
	char[] arr = s.ToCharArray();
	Array.Reverse(arr);
	return new string(arr);
    }
}

class Program
{
    static void Main()
    {
	Console.WriteLine(StringHelper.ReverseString("framework"));
	Console.WriteLine(StringHelper.ReverseString("samuel"));
	Console.WriteLine(StringHelper.ReverseString("example string"));
    }

- King October 24, 2016 | 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