Qualcomm

  www.qualcomm.com
  www.qualcomm.com

Interview Question

Intern Interview(Student Candidate) Hyderābād (India)

Swapping integers without using additional space

Answer

Interview Answer

3 Answers

4

a= a(xor)b,
b= a(xor)b,
a=a(xor)b

Interview Candidate on May 3, 2012
1

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

Kartik Kukreja on Jul 23, 2012
1

Doesn't work if a and b are 32 bit integer. We might have over flow in a+b. a(xor)b will not have any overflow

Rakesh Surapaneni on Jul 23, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.