Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Swap Number Without Temporary Variable
EASY
15 mins
11 upvotes
Bit Manipulation
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Bit Manipulation
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Swap Number Without Temporary Variable

Contributed by
Dhruv Sharma
Easy
yellow-spark
0/40
Avg time to solve 15 mins
Success Rate 85 %
Share
11 upvotes

Problem Statement

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 ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
10 12 
-4 -5   
Sample Output 1:
12 10
-5 -4
Explanation of sample input 1:
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.
Sample Input 2:
2
1 2 
0 -5   
Sample Output 2:
2 1
-5 0
Reset Code
Full screen
Auto
copy-code
Console