Challenge - 5 Problems
XOR Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
XOR of a number with itself is zero, and XOR with zero is the number itself.
✗ Incorrect
All numbers except 2 appear twice, so XOR cancels them out leaving 2.
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
XOR cancels pairs, leaving the unique number.
✗ Incorrect
10 and 14 appear twice, so XOR cancels them, leaving 15.
❓ Predict Output
advanced2: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);
Attempts:
2 left
💡 Hint
XOR works with negative numbers as well.
✗ Incorrect
Pairs cancel out, leaving -3 as unique.
🧠 Conceptual
advanced2: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.
Attempts:
2 left
💡 Hint
Think about how XOR behaves with identical numbers.
✗ Incorrect
XOR of two identical numbers is zero, so all pairs cancel out leaving the unique number.
❓ Predict Output
expert2: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);
Attempts:
2 left
💡 Hint
All numbers except one appear twice.
✗ Incorrect
Pairs cancel out, leaving 500 as unique.
