Halliburton

  www.halliburton.com
  www.halliburton.com

Interview Question

Intern Interview(Student Candidate) Houston, TX

Brain Teaser: Swap two numbers without using a temporary

  third variable.
Answer

Interview Answer

3 Answers

1

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
1

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
1

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.