Bird
Raised Fist0

Given the intermediate state where left=3 (0b11), right=3 (0b11), and shift=2 after right-shifting both numbers until equal, what was the original input range?

hard🔄 Reverse Engineer Q9 of Q15
Bit Manipulation - Bitwise AND of Numbers Range
Given the intermediate state where left=3 (0b11), right=3 (0b11), and shift=2 after right-shifting both numbers until equal, what was the original input range?
Aleft=12, right=15
Bleft=0, right=3
Cleft=12, right=13
Dleft=3, right=15
Step-by-Step Solution
Solution:
  1. Step 1: Recall that left and right are shifted right by 'shift' times to become equal

    Here, left=3, right=3 after shifting 2 times means original numbers were left<<2 and right<<2 plus possible bits.
  2. Step 2: Calculate original left = 3 << 2 = 12, original right must be between 12 and 15 to become 3 after shifting

    Only right=13 fits the condition (13 >> 2 = 3).
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Shifted values and shift count match original range [OK]
Quick Trick: Original = shifted value << shift count [OK]
Common Mistakes:
MISTAKES
  • Not applying shift count correctly
  • Assuming right is max shifted value
Trap Explanation:
PITFALL
  • Candidates often forget to reverse the shift or consider range boundaries properly.
Interviewer Note:
CONTEXT
  • Tests ability to reverse engineer inputs from intermediate algorithm state.
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