Pattern Recognition Drill
Medium Bit Manipulation
The Problem
Return the bitwise AND of all numbers in range [m, n].
What approach would you use?
Think about it before scrolling down.
Shift m and n right until equal, count shifts. Shift result back left. Common prefix method. O(32).
Common Trap
Don't loop from m to n — that's O(n-m). The bit-shift approach is O(log n).