Question bank › Bit Manipulation
Dsa Bit Manipulation Easy

Longest Sequence of Set Bits After Flipping

You are given an integer `n`. Your goal is to find the longest sequence of consecutive 1s in the binary representation of `n` after flipping exactly one 0 to a 1. Input: - A single integer `n` (0 <= n <= 1000000) Output: - Output the length of the longest sequence of 1s after one flip. Example: Input: 14 Output: 4 Explanation: The binary representation of 14 is 1110, flipping the last 0 gives us 1111, which has a sequence of 4 consecutive 1s.

Key concepts

bit_manipulationflippingsequences

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.