Visa Inc. Interview Question

How to swap two variables without a temp

Interview Answers

Anonymous

May 11, 2015

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

2

Anonymous

May 5, 2015

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

2

Anonymous

Mar 9, 2016

What if the variable is big. like the max value of an integer. How do we do this without changing it to long (which is easy but obviously not the solution) use bitwise operations. a=3 b=4 a = a xor b xor a b = a xor b xor b