iq.lab
Python sleeps until you run code
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) ≤ 10^5

  • Every item is 0 or 1.

⌘+Enter runs 0:00Python sleeps until you run code
Run examples checks the examples. Submit runs every test, including edge cases and a large input.