Recall & Review
beginner
What does XOR operation do when applied between two same bits?
XOR of two same bits is 0. For example, 1 XOR 1 = 0 and 0 XOR 0 = 0.
Click to reveal answer
intermediate
Why XOR of all elements in an array with exactly two non-repeating elements results in XOR of those two unique elements?
Because XOR of two same numbers is 0, all repeating elements cancel out, leaving XOR of only the two unique elements.
Click to reveal answer
intermediate
How do you find a set bit in XOR of two unique numbers to separate them?
Find the rightmost set bit (bit with value 1) in the XOR result using expression: xor & (-xor). This bit differs between the two unique numbers.
Click to reveal answer
intermediate
Explain the step to separate array elements into two groups using the set bit.
Divide elements into two groups: those with the set bit and those without. XOR each group separately to find the two unique numbers.
Click to reveal answer
beginner
What is the time complexity of finding two non-repeating elements using XOR?
The time complexity is O(n) because we traverse the array a constant number of times.
Click to reveal answer
What is the XOR of a number with itself?
✗ Incorrect
XOR of a number with itself is always 0.
If XOR of all elements in an array is 6, what does this represent when exactly two elements are unique?
✗ Incorrect
The XOR of all elements equals XOR of the two unique elements after canceling duplicates.
How do you find the rightmost set bit in a number x?
✗ Incorrect
x & (-x) isolates the rightmost set bit in x.
After finding the rightmost set bit, how are elements grouped?
✗ Incorrect
Elements are grouped based on whether the set bit is 1 or 0 in their binary form.
What is the main advantage of using XOR to find two unique elements?
✗ Incorrect
XOR method finds unique elements in linear time and constant space.
Describe the step-by-step process to find two non-repeating elements in an array using XOR.
Think about how XOR cancels duplicates and how to separate elements by a differing bit.
You got /4 concepts.
Explain why XOR operation helps in identifying unique elements in an array where all others repeat twice.
Focus on how XOR behaves with pairs and unique values.
You got /4 concepts.