Dsa
Bit Manipulation
Easy
Distinct Bit Counts
Given an integer n, return the number of distinct integers you can form using exactly the bits of n, ignoring any leading zeros.
For example, if n = 5 (binary: 0101), you can form the integers 1 (0001), 2 (0010), 3 (0011), 4 (0100), and 5 (0101). Therefore, the output should be 5.
Input:
A single integer n (0 ≤ n ≤ 10^9)
Output:
The number of distinct integers that can be formed.
Example:
Input:
5
Output:
5
Key concepts
bit manipulationcounting
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