Longest run of ones
A free easy coding practice problem. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.
- Difficulty
- Easy
- Type
- Function
- Languages
- JavaScript, TypeScript or Python
Problem
bits is an array of 0s and 1s. Return the length of the longest run of consecutive 1s.
Function signature
// JavaScript
function longestOnes(bits)
// TypeScript
function longestOnes(bits: any): any
// Python
def longest_ones(bits):Examples
longestOnes([1,1,0,1,1,1])→3longestOnes([0,0])→0
How checking works
Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.