Dsa
Bit Manipulation
Medium
Bitwise Complement of Range
Given an integer n and two integers l and r, calculate the bitwise complement of each number in the range [l, r] and return the sum of these complements.
Input format:
The first line contains an integer n (1 <= n <= 10^6).
The second line contains two space-separated integers l and r (0 <= l <= r <= n).
Output format:
Print a single integer, the total sum of bitwise complements.
Example:
Input: 5
1 3
Output: 6
Key concepts
bit_manipulationcomplement
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