0
0
DSA Pythonprogramming~20 mins

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

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
XOR Mastery Badge
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 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)
A0
B4
C5
D2
Attempts:
2 left
💡 Hint
XOR of a number with itself is 0, and XOR with 0 is the number itself.
Predict Output
intermediate
2: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)
A-3
B-1
C0
D-2
Attempts:
2 left
💡 Hint
XOR works the same with negative numbers as with positive.
🔧 Debug
advanced
2: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)
ANo error, prints 3
BSyntaxError
CTypeError
DValueError
Attempts:
2 left
💡 Hint
XOR operator requires both operands to be integers.
🧠 Conceptual
advanced
2: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)
An
Bn-1
Cn+1
D1
Attempts:
2 left
💡 Hint
The XOR happens once per element in the loop.
🚀 Application
expert
3: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)
A20
B30
C14
D10
Attempts:
2 left
💡 Hint
Pairs cancel out, leaving the unique number.