Skip to content
HTQHow To Quant
← Problem Bank

Number Swap

CalcEasy~5 min· Algorithms
Problem

Swap the values of two integer variables a and b without using a temporary variable. You may use arithmetic or bitwise operations, but you cannot declare any third variable.

Variant

Assume overflow does not occur for the arithmetic version (and note where it would bite you in real code).