easyLoops and basics target 15 min
Longest run of ones
A list bits holds only 0s and 1s. Return the length of the longest unbroken run of 1s.
Example 1
Input
bits = [1, 1, 0, 1, 1, 1]Output3The last three items are a run of three 1s.
Example 2
Input
bits = [1, 0, 1, 1, 0, 1]Output2Constraints
1 ≤ len(bits) ≤ 105
Every item is 0 or 1.
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.
Run examples checks the examples. Submit runs every test, including edge cases and, when the problem has one, a speed check on a large input.