FastPrepBitwise AND of Numbers Range

Bitwise AND of Numbers Range

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

Given two nonnegative integers left and right with left <= right, return the bitwise AND of every integer in the inclusive range [left, right].

Function

rangeBitwiseAnd(left: int, right: int) → int

Examples

Example 1

left = 5right = 7return = 4

5 AND 6 AND 7 equals 4.

Example 2

left = 0right = 0return = 0

The range contains only zero.

Constraints

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

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int rangeBitwiseAnd(int left, int right) {
    // Write your code here.
}
left5
right7
expected4
Checking account…