Bird
Raised Fist0

Consider the trie-based maximum XOR code. What is the output for input array [0] (single element)?

medium🧾 Code Trace Q4 of Q15
Bit Manipulation - Maximum XOR of Two Numbers
Consider the trie-based maximum XOR code. What is the output for input array [0] (single element)?
A1
B0
CNone (error)
DUndefined behavior
Step-by-Step Solution
Solution:
  1. Step 1: Insert single number 0 into trie.

    Trie has only one path for bits all zero.
  2. Step 2: findMaxXor tries to find toggled bits but none exist.

    Since only one number, no pair to XOR with, code tries to traverse missing toggled bit.
  3. Step 3: The code calls node.children.get(bit, node) which returns node itself if bit not found, avoiding error.

    Thus, max_xor remains 0.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Single element input returns 0 as max XOR [OK]
Quick Trick: Single element input returns 0 max XOR [OK]
Common Mistakes:
MISTAKES
  • Assuming code handles single element gracefully but expecting error
Trap Explanation:
PITFALL
  • Candidates overlook that code returns 0 for single element input.
Interviewer Note:
CONTEXT
  • Tests edge case handling and code robustness in trie traversal.
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