← Bit Manipulation

Pattern Recognition Drill

#88 — Bitwise AND of range

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.

Key Signals

Bit Manipulation

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).

← #87 #89 →