 All Problems
Bitwise AND of Numbers Range
medium
bit manipulation
amazon
google
facebook

Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive.

Example 1:

Input:  5 7
Output: 4

(5 AND 6 AND 7 = 100 AND 110 AND 111 = 100 = 4)

Example 2:

Input:  0 0
Output: 0

Example 3:

Input:  1 2147483647
Output: 0

Constraints:

  • 0 ≤ left ≤ right ≤ 2³¹ - 1

Input format: Two space-separated integers on one line.

Output format: The bitwise AND of the range.

Run to check your code against the sample cases, or submit to run every case