Dsa
Bit Manipulation
Easy
Longest Sequence of 1s
Given an integer n, find the length of the longest contiguous sequence of 1s in the binary representation of n.
Input:
A single integer n (0 ≤ n ≤ 10^9)
Output:
The length of the longest sequence of 1s.
Example:
Input:
29
Output:
2
Explanation: 29 in binary is 11101, the longest sequence of 1's is 11, which has length 2.
Key concepts
bit manipulationsequence
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