Longest Consecutive One Bits in a 32-Bit Integer
Problem statement
Given a non-negative signed 32-bit integer value, return the maximum number of consecutive 1 bits in its 32-bit binary representation.
Leading zeroes are included conceptually but do not affect the result.
Function
longestOneBitRun(value: int) → intExamples
Example 1
value = 1783return = 41783 is binary 11011110111; the longest run has length four.
Example 2
value = 0return = 0There are no one bits.
Example 3
value = 31return = 531 is five consecutive one bits.
Constraints
0 <= value <= 2,147,483,647.