Microsoft Interview Question for Software Engineer / Developers






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

James comment is insightful.
Joker's explanation is good.

- XYZ September 23, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

swap (a,b) {
a = a + b
b = a - b
a = a - b
}

- srihari January 06, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

swap(a,b)
{
a = a^b;
b = a^b;
a = a^b;
}

- Jack January 06, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

there could be a problem if one of then is 0

- Anonymous March 04, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

it works perfect u dumbo!

- Anonymous November 29, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks Mr. Anonymous!

- Jack November 29, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Subtraction/addition may be less efficient when expanded to assembly.

- Jack January 06, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is wrong.

Adding and subtracting only takes one clock. While multiply takes 6-8 clocks, division takes from 40-80 clocks.

- Nil March 26, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Shouldn't the question be swap two numbers in place?Just wondering..

- Srini January 10, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Srini, since we are not using an extra temporary variable, I am assuming that the two methods discussed above are in-place.

- srihari January 10, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Jack, i didn't get u r answer. what does a^b mean?

- dkr March 21, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a^b , we are dealing with XOR here.

- HotDogMumboJumboKudo March 22, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

first one could cause overflow; second should be rite

- James May 10, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

in case it is int numbers
a and be should be float or double
for a = 5, b=6
a = (b*10) + a; // = 65
b = a; // = 65

a = (a/10); // automatic casting from double
b = (b%10);

- Eila May 29, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a=a^b;
b=a^b=(a^b)^b=a^0=a
a=a^b=(a^b)^(a)=a^a^b=0^b=b

a=a+b;
b=a-b=(a+b)-b=a
a=a-b=(a+b)-a=b
-------------------------------------
Groovy!!

- Joker September 28, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a=a^b;
b=a^b=(a^b)^b=a^0=a
a=a^b=(a^b)^(a)=a^a^b=0^b=b

a=a+b;
b=a-b=(a+b)-b=a
a=a-b=(a+b)-a=b
-------------------------------------
Groovy!!

- Joker September 28, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a=a^b;
b=a^b=(a^b)^b=a^0=a
a=a^b=(a^b)^(a)=a^a^b=0^b=b

a=a+b;
b=a-b=(a+b)-b=a
a=a-b=(a+b)-a=b
-------------------------------------
Groovy!!

- Joker September 28, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a^=b^=a^=b;

- Li Ze March 19, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

b=(a+b)-(a=b);

- Anonymous September 21, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Guys, check out for the case when a == b. The XOR logic will make a = b and b = b. Sh, the entire xor logic should be in if (a != b) { XOR logic goes here }

- Anonymous July 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What is the problem? Since a==b, then a = b and b = b is the correct result.

- Anonymous October 30, 2009 | 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