Swap Number Without Temporary Variable

Given two variables ‘X’ and ‘Y’. Your task is to swap the number without using a temporary variable or third variable.

Swap means the value of ‘X’ and ‘Y’ must be interchanged. Take an example ‘X’ is 10 and ‘Y’ is 20 so your function must return ‘X’ as a 20 and ‘Y’ as a 10.

Input format:
The first line of input contains an integer ‘T’ denoting the number of test cases.

Next ‘T’ lines contain two space-separated integers ‘X’ and ‘Y’ which represent the next ‘T’ test cases. 
Output Format
For each test case, return an array/vector that contains two integers ‘X’ and ‘Y’ with a swapped value.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 2*10^5
-10^9 <= X,Y <= 10^9

Where ‘T’ is the total number of test cases, ‘X’ and ‘Y’ denotes two given integer variables.

Time limit: 1 second
Be the first one to answer
Add answer anonymously...
Nvidia Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter