Repetive Ones
ARRAY

Problem

Given an array nums consisting of only 0s and 1s, find the maximum number of consecutive 1s that occur in the array.

Examples

repetiveOnes([1, 1, 1, 1, 0, 1]) // returns 4 // The longest sequence of ones is four // at the beginning of the array repetiveOnes([1, 0, 1, 0, 1, 0]) // returns 1 // The sequences of ones are all separated by zeros // so the longest sequence is 1 repetiveOnes([1, 1, 0, 0, 1, 1, 1, 0, 1, 1]) // returns 3 // The longest sequence of ones is three // found in the middle of the array
Loading...