Pergunta de entrevista da empresa SEITech Solutions

How can you swap 2 variables?

Resposta da entrevista

Sigiloso

4 de ago. de 2024

Instead of doing a naive solution that requires a third temporary variable and thus wastes memory, utilize a bit-wise XOR operator to swap the variables in place. X = X ^ Y -> Y = X ^ Y -> X = X^Y. After the third line X and Y's data should be swapped.