How would you swap two integers without using a temporary variable? Seen it before? Pass. Not seen it before? Fail.
How would you swap two integers without using a temporary variable? Seen it before? Pass. Not seen it before? Fail.
In nearly 30 years of diverse coding experience, I've never once encountered a situation where this solution would be useful.
Steps, mostly driven by just basically knowing the goal and that there's not many operations that could possibly help:
"a" "b"
"a+b" "b"
"a+b" "-a"
"b" "-a"
"b" "a"
Then once you have that, you can enumerate the downsides to that, look for more efficient and less error-prone ways to proceed.
We were looking for the solution based on XOR which works with only two registers.
We wish you luck with your job search elsewhere.
These interview questions are fairly shit, but they're not _that_ shit, and the people giving them are doing their best.