Bird
0
0
DSA Cprogramming~20 mins

Find the Only Non Repeating Element Using XOR in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
XOR Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this code snippet?
Given an array where every element repeats twice except one, find the unique element using XOR.
DSA C
int arr[] = {2, 3, 5, 4, 5, 3, 4};
int n = 7;
int unique = 0;
for (int i = 0; i < n; i++) {
    unique ^= arr[i];
}
printf("%d\n", unique);
A5
B2
C3
D4
Attempts:
2 left
💡 Hint
XOR of a number with itself is zero, and XOR with zero is the number itself.
Predict Output
intermediate
2:00remaining
What is the output of this XOR operation on the array?
Find the unique element in the array using XOR.
DSA C
int arr[] = {10, 14, 10, 14, 15};
int n = 5;
int unique = 0;
for (int i = 0; i < n; i++) {
    unique ^= arr[i];
}
printf("%d\n", unique);
A15
B10
C0
D14
Attempts:
2 left
💡 Hint
XOR cancels pairs, leaving the unique number.
Predict Output
advanced
2:00remaining
What is the output of this code with negative numbers?
Find the unique element using XOR in an array with negative and positive integers.
DSA C
int arr[] = {-1, -2, -2, -1, -3};
int n = 5;
int unique = 0;
for (int i = 0; i < n; i++) {
    unique ^= arr[i];
}
printf("%d\n", unique);
A-3
B-1
C-2
D0
Attempts:
2 left
💡 Hint
XOR works with negative numbers as well.
🧠 Conceptual
advanced
2:00remaining
Why does XOR help find the unique element in an array where all others repeat twice?
Choose the best explanation for why XOR operation can find the only non-repeating element.
AXOR sorts the array and picks the middle element as unique.
BXOR adds all numbers together and divides by two to find the unique number.
CXOR multiplies all numbers and the unique number remains after division.
DXOR of a number with itself is zero, so pairs cancel out, leaving the unique number.
Attempts:
2 left
💡 Hint
Think about how XOR behaves with identical numbers.
Predict Output
expert
2:00remaining
What is the output of this code with a large array?
Find the unique element using XOR in a large array where all elements except one repeat twice.
DSA C
int arr[] = {100, 200, 300, 100, 200, 400, 300, 500, 400};
int n = 9;
int unique = 0;
for (int i = 0; i < n; i++) {
    unique ^= arr[i];
}
printf("%d\n", unique);
A300
B400
C500
D100
Attempts:
2 left
💡 Hint
All numbers except one appear twice.