Skip to content
RED SAGSkills
easy15 ptsarrays

Longest Run of Ones

A health check records 1 for a successful probe and 0 for a failed one. Given the array checks, return the length of the longest unbroken streak of 1s.

Example 1

Input: checks = [1, 1, 0, 1, 1, 1, 0]
Output: 3

Example 2

Input: checks = [0, 0]
Output: 0

Constraints

  • 1 <= checks.length <= 10^5
  • checks[i] is 0 or 1.
Hint 1

Keep a running count that resets to 0 on a failure.

Hint 2

Track the largest value the running count reaches.

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Game Developer, Automation Test Engineer, Site Reliability Engineer, Embedded Systems Engineer

Run checks your code on 2 sample tests. Submit runs all 6 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.