LeetCode 201: Bitwise AND of Numbers Range

Let’s solve LeetCode problem 201: Bitwise AND of Numbers Range. The instructions are as follows: Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive. Constraints: 0 <= left <= right <= 2^31 - 1 Let’s dive in! Looking at the common binary prefix Let \(l\) and \(r\) denote left and right, respectively. I’ll denote binary strings with 0b..., for example 5 can be written as 0b101. ...

January 4, 2026 · 5 min · David Nabergoj