Dsa
Bit Manipulation
Medium
Binary Swap Count
Given an integer N, count how many pairs of bits in the binary representation of N can be swapped such that the result remains less than N. Print the count of such pairs.
Example:
Input:
10
Output:
1
(For N=10, bit representation is 1010, swapping the last two bits (1 and 0) results in 8 which is less than 10.)
Key concepts
bit_manipulationswapping_bits
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