Recall & Review
beginner Click to reveal answer
What does XOR operation do when applied between two identical bits?
XOR of two identical bits is 0. For example, 1 XOR 1 = 0 and 0 XOR 0 = 0.
beginner Click to reveal answer
Why does XOR help find the only non-repeating element in an array where every other element repeats twice?
Because XOR of a number with itself is 0, all repeating elements cancel out, leaving only the non-repeating element after XORing all elements.
beginner Click to reveal answer
What is the time complexity of finding the only non-repeating element using XOR?
The time complexity is O(n), where n is the number of elements in the array, because we XOR all elements once.
beginner Click to reveal answer
TypeScript code snippet: How do you initialize the variable to store XOR result before looping through the array?
Initialize with 0 because XOR with 0 returns the other number unchanged. Example: let result = 0;beginner Click to reveal answer
What will be the output of XORing all elements in [2, 3, 2, 4, 3]?
4, because 2 XOR 3 XOR 2 XOR 4 XOR 3 = (2 XOR 2) XOR (3 XOR 3) XOR 4 = 0 XOR 0 XOR 4 = 4.
What is the result of XORing a number with 0?
✗ Incorrect
XOR with 0 leaves the number unchanged.
If every element except one appears twice in an array, what does XOR of all elements give?
✗ Incorrect
Pairs cancel out to 0, leaving only the unique element.
What is the initial value to start XOR accumulation when finding the unique element?
✗ Incorrect
Starting with 0 ensures XOR works correctly with all elements.
Which of these is NOT true about XOR operation?
✗ Incorrect
XOR of a number with 0 is the number itself, not 0.
What is the time complexity of the XOR method to find the unique element?
✗ Incorrect
We iterate once through the array, so time complexity is linear.
Explain how XOR operation helps find the only non-repeating element in an array where all other elements repeat twice.
Think about how pairs of identical numbers behave with XOR.
You got /4 concepts.
Write a simple TypeScript function to find the only non-repeating element in an array using XOR.
Use a for loop and XOR operator ^.
You got /4 concepts.
