Bitwise AND of Range
mediumFind bitwise AND of all numbers in range [left, right]
Bitwise AND of Range
Key Insight
Find common prefix of left and right. Bits that differ will become 0.
Step 1Problem
5
5
=0
0
0
0
0
1
0
1
6
6
=0
0
0
0
0
1
1
0
7
7
=0
0
0
0
0
1
1
1
76543210
AND all numbers from 5 to 7.
1 / 5