Challenge - 5 Problems
XOR Mastery Badge
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 using XOR to find the unique element?
Given the list
arr = [2, 3, 5, 4, 5, 3, 4], what will be printed after running the code below?DSA Python
arr = [2, 3, 5, 4, 5, 3, 4] unique = 0 for num in arr: unique ^= num print(unique)
Attempts:
2 left
💡 Hint
XOR of a number with itself is 0, and XOR with 0 is the number itself.
✗ Incorrect
All numbers except 2 appear twice. XOR cancels out duplicates, leaving 2 as the unique element.
❓ Predict Output
intermediate2:00remaining
What is the output of this XOR code with negative numbers?
Given
arr = [-1, -2, -2, -1, -3], what will the code print?DSA Python
arr = [-1, -2, -2, -1, -3] unique = 0 for num in arr: unique ^= num print(unique)
Attempts:
2 left
💡 Hint
XOR works the same with negative numbers as with positive.
✗ Incorrect
Pairs cancel out, leaving -3 as the unique number.
🔧 Debug
advanced2:00remaining
What error does this code raise?
What error will this code raise when trying to find the unique element using XOR?
DSA Python
arr = [1, 2, 2, 1, '3'] unique = 0 for num in arr: unique ^= num print(unique)
Attempts:
2 left
💡 Hint
XOR operator requires both operands to be integers.
✗ Incorrect
The string '3' cannot be XORed with an integer, causing a TypeError.
🧠 Conceptual
advanced2:00remaining
How many times is the XOR operation applied in this code?
Given an array of length n, how many XOR operations does the code below perform?
DSA Python
arr = [some list of length n] unique = 0 for num in arr: unique ^= num print(unique)
Attempts:
2 left
💡 Hint
The XOR happens once per element in the loop.
✗ Incorrect
The loop runs n times, applying XOR each time.
🚀 Application
expert3:00remaining
What is the unique element after XOR operations on this large array?
Given the array
arr = [10, 14, 10, 14, 20, 30, 20], what is the unique element found by XOR?DSA Python
arr = [10, 14, 10, 14, 20, 30, 20] unique = 0 for num in arr: unique ^= num print(unique)
Attempts:
2 left
💡 Hint
Pairs cancel out, leaving the unique number.
✗ Incorrect
All numbers except 30 appear twice, so 30 is the unique element.