Dsa
Bit Manipulation
Easy
Count Distinct Powers of Two
You are given an array of integers. Count how many distinct powers of two (2^0, 2^1, 2^2, ...) appear in the binary representations of the integers. For each integer, the corresponding power of two is the index of the bit that is set.
Input Format:
- The first line contains an integer n (1 ≤ n ≤ 100).
- The second line contains n space-separated integers.
Output Format:
- Print the count of distinct powers of two.
Example Input:
4
3 5 10 6
Example Output:
4
(From binaries: 11, 101, 1010, 110, we have distinct indices 0, 1, 2, 3).
Key concepts
bit_manipulationpowers_of_twocounting
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