Question bank › Bit Manipulation
Dsa Bit Manipulation Hard

Alternating Bits Count

You are given a non-negative integer 'n'. Your task is to count the number of bits that are set in 'n' such that no two adjacent bits are both set (1). It is a valid configuration if the binary representation does not have '11' adjacent. Input format: A single integer n (0 <= n <= 10^9). Output format: A single integer, the count of valid set bits. Example: If the input is '13', the binary representation is '1101', which has 2 valid set bits. So, the output should be '2'.

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.