Problem of the day
You are given two numbers 'a' and 'b' as input.
You must swap the values of 'a' and 'b'.
Input:
'a' = 8, 'b' = 5
Output:
5 8
Explanation:
Initially, the value of 'a' and 'b' is 8 and 5, respectively.
After swapping, the value of 'a' is 5, and the value of 'b' is 8.
The first and only input line contains two integers, 'a' and 'b', representing the two numbers.
Output Format:
The first line of output prints the swapped value of 'a' and 'b'.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 2
2 1
The output of the above test case is 2 1.
5 6
6 5
The output of the above test case is 6 5.
-10^5 <= 'a', 'b' <= 10 ^ 5
Time Limit: 1 sec
We can use a third variable.
Take input in two integer datatype variables, a and b. Create a temporary variable temp and initialize it equal to a. Now make a equal to b, and finally make b equal to temp. Print a and b.
O(1),
The Time Complexity is O(1).
O(1),
The Space Complexity is O(1).