Bitwise AND of Numbers Range

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
Inputleft = 5, right = 7
Output4
The bitwise AND of all numbers from 5 through 7 is 4.
Example 2
Inputleft = 0, right = 0
Output0
The only number in the range is 0, so the result is 0.

Constraints

  • 0 <= left <= right <= 2^31 - 1

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate