Bit Manipulation - Single Number III (Two Singles)Given the following code and input, what is the final returned list?A[2, 5]B[5, 4]C[4, 5]D[2, 4]Check Answer
Step-by-Step SolutionStep 1: Compute xor of all elementsxor = 2 ^ 4 ^ 2 ^ 5 = (2 ^ 2) ^ 4 ^ 5 = 0 ^ 4 ^ 5 = 1 (binary 0001)Step 2: Find rightmost set bit and partitionset_bit = xor & (-xor) = 1 & (-1) = 1. Partition nums by bit 1: group1 (bit set): 5, group2 (bit not set): 2,4,2. XOR group1 = 5, XOR group2 = 4.Final Answer:Option C -> Option CQuick Check:Output matches unique elements [OK]Quick Trick: Rightmost set bit partitions unique numbers correctly [OK]Common Mistakes:MISTAKESMixing order of outputIncorrect xor calculationMiscomputing set bitTrap Explanation:PITFALLCandidates often confuse xor or set bit calculation leading to wrong partitioning.Interviewer Note:CONTEXTTests ability to trace bitwise XOR and partitioning logic precisely.
Master "Single Number III (Two Singles)" in Bit Manipulation3 interactive learning modes - each teaches the same concept differentlyTry ItSolutionTrace
More Bit Manipulation Quizzes Bitwise AND of Numbers Range - Bitwise AND of Numbers Range - Quiz 12easy Find Two Missing Numbers - Find Two Missing Numbers - Quiz 6medium Generate All Permutations Using Bitmask DP - Generate All Permutations Using Bitmask DP - Quiz 5medium Gray Code - Gray Code - Quiz 4medium Maximum Product of Word Lengths - Maximum Product of Word Lengths - Quiz 11easy Maximum XOR of Two Numbers - Maximum XOR of Two Numbers - Quiz 12easy Number of 1 Bits (Hamming Weight) - Number of 1 Bits (Hamming Weight) - Quiz 8hard Single Number II (Three Copies) - Single Number II (Three Copies) - Quiz 5medium Single Number II (Three Copies) - Single Number II (Three Copies) - Quiz 6medium UTF-8 Validation - UTF-8 Validation - Quiz 12easy