Bitwise AND of Numbers Range

Given two integers left and right, return the bitwise AND of all numbers in the inclusive range [left, right]. Pattern focus: Clear Lowest Bit. The answer keeps only the shared prefix bits that survive after repeatedly clearing differing low bits.

Input Format

left = lower bound, right = upper bound

Output Format

bitwise AND of all integers in [left, right]

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • left, right must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

left = 5
right = 7

Output:

4

Explanation:

5 & 6 & 7 = 4.

Example 2:

Input:

left = 0
right = 0

Output:

0

Explanation:

A single value range returns the value itself.

Loading...
Bitwise AND of Numbers Range - Bit Manipulation