Dsa
Bit Manipulation
Hard
Reverse Bits in Range
You are given a non-negative integer 'n' and a range defined by two integers 'l' and 'r'. Your task is to reverse the bits of 'n' only in the specified range [l, r] (0-indexed from the right). Return the modified integer after the reversal.
Input format: The first line contains the integer 'n', and the second line contains the integers 'l' and 'r' (0 <= l <= r < 32).
Output format: A single integer which is the modified integer after reversing the bits in the range.
Example: For input '29
1 3', binary '11101' become '10111' after reversing bits in position [1, 3], so the output should be '23'.
Key concepts
bit manipulationbit reversal
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now