Numbers with exactly two set bits
How many integers with have exactly two set bits in their binary representation (i.e. popcount(n) == 2)?
Show hints (2)+
- Two set bits for distinct positions - count the pairs, don't scan.
- Usable positions are (since ); every pair , so the answer is .
Answer
Reveal answer →Final answer
21
Create a free account to see the full worked solution and track your progress.
Interview format: Trading Aptitude Tests, Prop Trading