Search topics...

Range Bitwise AND

medium
bitsTime: O(log n)Space: O(1)Frequency: 3

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

Example 1:

Input: left = 5, right = 7
Output: 4
Explanation: 5 (101) & 6 (110) & 7 (111) = 4 (100)

Example 2:

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

Example 3:

Input: left = 1, right = 2147483647
Output: 0
prefix-sumbit-manipulation