iq.lab
Python starts when a code cell comes near or you run one
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
Inputbits = [1, 1, 0, 1, 1, 1]Output3

The last three items are a run of three 1s.

Example 2
Inputbits = [1, 0, 1, 1, 0, 1]Output2
Constraints
  • 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.

⌘+Enter runs 0:00Python starts when a code cell comes near or you run one
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.