1361. Bitwise AND of Numbers Range

MediumBit ManipulationBit ManipulationCommon PrefixRange

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

Input: A JSON object {"left": <integer>, "right": <integer>} with left <= right.

Output: Return the AND of all integers in the range.

Examples

Example 1
Input: {"left":5,"right":7}
Output: 4
Explanation: The common prefix of 101 and 111 is 100 = 4.
Example 2
Input: {"left":0,"right":0}
Output: 0
Explanation: A single value range returns that value -> 0.

Constraints

Asked by

GoogleMicrosoftAmazonBloombergMeta
Solve this problem in the editor →