Question bank › Bit Manipulation
Dsa Bit Manipulation Medium

Flip Bit to Win

You are given an integer `n`, representing a binary number. You are allowed to flip exactly one bit (0 to 1 or 1 to 0). Determine the length of the longest sequence of consecutive 1s you can create after this flip. Print that length. Input: A single integer `n` (0 ≤ n ≤ 10^9). Output: A single integer, the maximum length of consecutive 1s after flipping a bit. Example: Input: 1775 Output: 8 Explanation: The binary representation of 1775 is 11011101111; flipping the bit at position 3 gives 11111101111, which has length 8.

Key concepts

bit_manipulationmax_sequenceflip

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