Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

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.

Detailed explanation

```
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
```

```
2
10 12
-4 -5
```

```
12 10
-5 -4
```

```
Test Case 1:
Given ‘X’ is 10 and ‘Y’ is 12. After swapping ‘X’ will be 12 and ‘Y’ will be 10.
Test Case 2:
Given ‘X’ is -1 and ‘Y’ is -5. After swapping ‘X’ will be -5 and ‘Y’ will be -4.
```

```
2
1 2
0 -5
```

```
2 1
-5 0
```