0 out of 464 challenges solved
Write a Python function `all_bits_unset_in_range(n, l, r)` that checks whether all the bits in the binary representation of the integer `n` are unset (i.e., 0) within the range `[l, r]` (inclusive). The range is 1-based, meaning the least significant bit is at position 1. #### Example Usage ```python [main.nopy] print(all_bits_unset_in_range(4, 1, 2)) # Output: True print(all_bits_unset_in_range(17, 2, 4)) # Output: True print(all_bits_unset_in_range(39, 4, 6)) # Output: False ``` #### Constraints - `n` is a non-negative integer. - `l` and `r` are positive integers such that `1 <= l <= r`. - The function should return a boolean value: `True` if all bits in the range are unset, otherwise `False`.
def all_bits_unset_in_range(n, l, r):
"""
Check if all bits in the binary representation of n are unset within the range [l, r].
Args:
n (int): The number to check.
l (int): The starting position of the range (1-based).
r (int): The ending position of the range (1-based).
Returns:
bool: True if all bits in the range are unset, False otherwise.
"""
# Placeholder for the solution
pass