Qualcomm Interview Question for Software Engineer in Tests






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

a=a^b
b=a^b
a=a^b

- Anonymous October 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

is correct!!!! (:

- dumdum May 24, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

a = a+b
b = a-b
a = a-b

- sallle October 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Unfold the xor to see why this works:

void Swap(int &a, int &b)
{
    a ^= b;
    b ^= a;
    a ^= b;
}

- jekdoce October 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

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

in the first step a will get the value of b. But in the second step a^b yields zero.

- Anonymous December 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

nice solution

- Anonymous December 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Rajeev January 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a^=b^=a^=b;

- Krishna March 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a = a-b
b = a+b
a = b-a

- Hari July 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

$a,$b = $b, $a

- Anonymous February 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

$a,$b = $b, $a

- Anonymous February 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The most simple algorithm for the above problem is to follow the steps below:
1. First, we will take the xor of the two numbers such that the first number remains in the first variable itself.
2. We will then, take xor of the two numbers again which will put the first number in the second variable also, and then finally take xor so that the second number comes to the first variable
Implementation:

a = a^b;
b = a^b;
a = a^b;

- swapnilkant11 July 19, 2019 | 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