FastPrepLongest Consecutive One Bits in a 32-Bit Integer

Longest Consecutive One Bits in a 32-Bit Integer

Google logoGoogle● EasyNEW GRADPHONE SCREEN
Learn

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) → int

Examples

Example 1

value = 1783return = 4

1783 is binary 11011110111; the longest run has length four.

Example 2

value = 0return = 0

There are no one bits.

Example 3

value = 31return = 5

31 is five consecutive one bits.

Constraints

  • 0 <= value <= 2,147,483,647.

More Google problems

See Google hiring insights
public int longestOneBitRun(int value) {
    // Write your code here.
}
value1783
expected4
Checking account…