Bird
Raised Fist0

Consider the following code snippet implementing the trie-based maximum XOR finder. Given the input array [2, 8], what is the return value of findMaximumXOR([2, 8])?

easy🧾 Code Trace Q12 of Q15
Bit Manipulation - Maximum XOR of Two Numbers
Consider the following code snippet implementing the trie-based maximum XOR finder. Given the input array [2, 8], what is the return value of findMaximumXOR([2, 8])?
A2
B8
C10
D0
Step-by-Step Solution
Solution:
  1. Step 1: Insert numbers 2 and 8 into trie

    2 in binary: 000...0010, 8 in binary: 000...1000. Trie stores bits for both numbers.
  2. Step 2: For each number, find max XOR partner

    For 2, try to find bits opposite to 2's bits in trie. At bit 3 (8's highest set bit), toggled bit exists, so max_xor |= 8. At bit 1, toggled bit exists, max_xor |= 2. Total max_xor = 10.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    2 XOR 8 = 10, which is maximum XOR [OK]
Quick Trick: XOR of 2 and 8 is 10, max XOR found [OK]
Common Mistakes:
MISTAKES
  • Confusing max_xor with input number
  • Off-by-one bit indexing
  • Returning XOR with self
Trap Explanation:
PITFALL
  • Candidates may forget to check toggled bit first, leading to lower XOR values.
Interviewer Note:
CONTEXT
  • Tests ability to trace bitwise trie traversal and XOR calculation.
Master "Maximum XOR of Two Numbers" in Bit Manipulation

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bit Manipulation Quizzes