1

Reset in Range

Difficulty: EASY
Avg. time to solve
15 min
Success Rate
90%

Problem Statement

You are given a number. You need to reset the bits from Lth position to Rth position. LSB is at first position (R = 1).

Example: Given number is 94 (1011110), L = 5 and R = 2. If we reset bits from L to R in the number, then the resultant number would be 64 (1000000).

Input Format:
The first line contains a single integer ‘T’ representing the number of test cases. 

The first line of each test case will contain a single integer ‘N’ which denotes the input number whose ‘L’th to ‘R’th bit needs to be reset.

The second line of each test case will contain two space separated integers ‘L’ and ‘R’, where ‘L’ denotes the left bound of the range of bits to be reset and ‘R’ denotes the right bound of the range of bits to be reset. 
Output Format:
For each test case, print the number after resetting the Lth to Rth bit in the number.

Output for every test case will be printed in a separate line.
Note:
You don’t need to print anything; It has already been taken care of.
Follow up:
Can you solve it in O(1) time and space complexity?
Constraints:
1 <= T <= 10
1 <= N <= 10^9
1 <= R <= L <= 31

Time Limit: 1 sec
Sample Input 1:
2
10
2 1
15    
3 2
Sample Output 1:
8
9
Explanation For Sample Input 1:
In the first test case, the given number is 10 (1010) , ‘L’=2 and ‘R’=1. After reset of 2nd to 1st bit, we get the resultant value as 8 (1000).

In the second test case, the given number is 15 (1111), ‘L’=3, and ‘R’=2. After reset of 3rd to 2nd, we get the resultant value as 9 (1001).
Sample Input 2:
2
23 
4 2
31   
3 1   
Sample Output 2:
17
24
Explanation For Sample Input 2:
In the first test case, the given number is 23 (10111) , ‘L’=4 and ‘R’=2. After reset of 4th to 2nd, we get the resultant value as 17 (10001).

In the second test case, the given number is 31 (11111), ‘L’=3, and ‘R’=1. After reset of 3rd to 1st, we get the resultant value as 24 (11000).
Reset Code
Full screen
copy-code
Console