← Back to Games

🔍 XOR Detective

Find the single non-duplicate element - pairs cancel with XOR!

🎯 The Investigation
Running XOR Result
0
🎉 Found the unique element!

📚 XOR Property for Finding Unique

When every element appears twice except one:

// XOR Property: a ^ a = 0
// All pairs cancel out!

result = 0;
for (num in array) {
  result = result ^ num;
}
// result = the unique element

// Example: [4, 1, 2, 1, 2]
// 4 ^ 1 ^ 2 ^ 1 ^ 2
// = 4 ^ (1 ^ 1) ^ (2 ^ 2)
// = 4 ^ 0 ^ 0
// = 4 ✓