Bird
Raised Fist0

What is the output of the optimal bitwise AND range function for input left=0, right=0?

medium🧾 Code Trace Q4 of Q15
Bit Manipulation - Bitwise AND of Numbers Range
What is the output of the optimal bitwise AND range function for input left=0, right=0?
A0
B1
CError or infinite loop
D-1
Step-by-Step Solution
Solution:
  1. Step 1: Check loop condition with left=0, right=0

    Since right is not greater than left, loop does not execute.
  2. Step 2: Return right which is 0

    Output is 0 as expected for single element range.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Single number AND with itself is the number [OK]
Quick Trick: Loop skips if left == right [OK]
Common Mistakes:
MISTAKES
  • Assuming loop runs even if left == right
  • Returning wrong default value
Trap Explanation:
PITFALL
  • Candidates sometimes expect loop to run or error on single-element range, but it does not.
Interviewer Note:
CONTEXT
  • Tests handling of edge cases in bitwise AND range code.
Master "Bitwise AND of Numbers Range" 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