Recall & Review
beginner
What is the main idea behind using XOR to find two non-repeating elements in an array?
XOR of all elements gives XOR of the two unique elements because pairs cancel out. Then, use a set bit to separate elements into two groups to find each unique element.
Click to reveal answer
beginner
Why do pairs of repeating elements cancel out when XORed together?
Because XOR of a number with itself is 0, so pairs XOR to 0 and do not affect the final XOR result.
Click to reveal answer
intermediate
How do you find a set bit in the XOR of two unique elements?
Use expression (xor & -xor) to isolate the rightmost set bit, which helps to divide elements into two groups.
Click to reveal answer
beginner
What is the time complexity of finding two non-repeating elements using XOR?
O(n), where n is the number of elements in the array, because we scan the array a few times linearly.
Click to reveal answer
intermediate
Explain why dividing elements into two groups based on a set bit helps find the unique elements.
The two unique elements differ at that bit, so grouping by that bit separates them. XORing each group gives one unique element each.
Click to reveal answer
What does XOR of all elements in an array with exactly two unique elements and others repeating give?
✗ Incorrect
Pairs cancel out in XOR, leaving XOR of the two unique elements.
How do you find a bit that differs between the two unique elements after XOR?
✗ Incorrect
The expression (xor & -xor) isolates the rightmost set bit.
Why do we divide elements into two groups based on the set bit?
✗ Incorrect
The two unique elements differ at that bit, so grouping separates them.
What is the time complexity of the XOR method to find two unique elements?
✗ Incorrect
The method scans the array a few times linearly, so O(n).
What is the XOR of a number with itself?
✗ Incorrect
XOR of a number with itself is always 0.
Explain step-by-step how to find two non-repeating elements in an array using XOR.
Think about how XOR cancels pairs and how to separate unique elements.
You got /4 concepts.
Why does the XOR method work efficiently for finding two unique elements in an array where others repeat twice?
Focus on XOR properties and grouping by bit.
You got /4 concepts.
