Interview Question

Interview(Student Candidate) Houston, TX

Brain Teaser: Swap two numbers without using a temporary

  third variable.

Interview Answer

3 Answers


I provided a solution involving using multiplication/division to store the information about both numbers in a single variable

Interview Candidate on Oct 21, 2012

Example: A=5, B=7 B=B*A^2=7*25 A=B/(A^2)=7*25/25=7 B=sqrt(B/A)=sqrt(7*25/7)=5

Anonymous on Nov 6, 2012

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

Syed Naveed on Oct 22, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.