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

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

is correct!!!! (:

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

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

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;
}``````

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

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

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

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

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

nice solution

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

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

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

a^=b^=a^=b;

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

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

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

\$a,\$b = \$b, \$a

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

\$a,\$b = \$b, \$a

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;``````

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.

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.