Bird
Raised Fist0

What is the output of the XOR-based single number function when the input array contains only one element [7]?

medium🧾 Code Trace Q4 of Q15
Bit Manipulation - Single Number (XOR Self-Cancellation)
What is the output of the XOR-based single number function when the input array contains only one element [7]?
A0
B7
CError or exception
D-1
Step-by-Step Solution
Solution:
  1. Step 1: Trace XOR with single element

    0 · 7 = 7
  2. Step 2: Return result

    Since only one element, result is that element itself.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Single element returns itself [OK]
Quick Trick: XOR with zero returns the number itself [OK]
Common Mistakes:
MISTAKES
  • Assuming empty input causes error
  • Forgetting XOR with zero returns number
Trap Explanation:
PITFALL
  • Some think single element input causes error or zero output.
Interviewer Note:
CONTEXT
  • Tests edge case handling and code trace skills.
Master "Single Number (XOR Self-Cancellation)" 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