Trains the technique from
LeetCode 201Bitwise AND of Numbers RangeThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Take every whole number from left to right, both ends included, and combine the lot with a bitwise AND.
Return the result.
Example 1
All four numbers agree on their top bits and differ beneath, so only the agreed part survives.
Example 2
The range crosses a power of two, so no bit place stays set right the way through.
Example 3
The range holds a single number, so that number is the result.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def range_bitwise_and(left: int, right: int) -> int:public int rangeBitwiseAnd(int left, int right)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.