Bitwise AND of Numbers Range

Medium

Description

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

Examples

Input:left = 5, right = 7
Output:4
Explanation:

5 & 6 & 7 = 4.

Input:left = 0, right = 0
Output:0
Explanation:

Single element range.

Input:left = 1, right = 2147483647
Output:0
Explanation:

Large range results in 0.

Constraints

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

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!