![]() |
VOOZH | about |
Given a non-negative number n and two values l and r. The problem is to check whether all the bits are unset or not in the range l to r in the binary representation of n.
Constraint: 1 <= l <= r <= number of bits in the binary representation of n.
Examples:
Input : n = 17, l = 2, r = 4 Output : Yes (17)10 = (10001)2 The bits in the range 2 to 4 are all unset. Input : n = 36, l = 3, r = 5 Output : No (36)10 = (100100)2 The bits in the range 3 to 5 are all not unset.
Approach: Following are the steps:
Output:
Yes
Time Complexity : O(1)
Auxiliary Space: O(1)