Longest Consecutive One Bits in a 32-Bit Integer
Updated
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.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Count the 1 Bits in a 32-Bit ValueAmazon · PHONE SCREEN
- Find the Unique Element Among PairsChubb · PHONE SCREENChubb interview questions
- XOR Pseudorandom SequenceBaseten · PHONE SCREENBaseten interview questions
- Maximize Binary XOR with a Set-Bit LimitJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Swap Adjacent NibblesArista Networks · PHONE SCREENArista Networks interview questions
- The One Repeated NumberAdobe · PHONE SCREENAdobe interview questions
- CPU Register Bitwise OperationsHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- Integer to Binary RepresentationThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Spelling Bee Word FilterBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Find the Element With Odd FrequencyZscaler · PHONE SCREENZscaler interview questions