All problems
0183EasyArray

Longest Online Panel Run

Tracked in this browser only
Write code

Trains the technique from

LeetCode 485Max Consecutive Ones

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A solar farm polls its panels along one long row and hands you the reply as status, listed in the order the panels sit on the row. status[i] is 1 when panel i answered and 0 when it did not.

A crew wants to know the widest stretch of neighbouring panels that all answered. Return the number of panels in the longest stretch that contains no silent panel, or 0 when no panel answered at all.

Examples

Example 1

Input
status = [1, 1, 1, 0, 1, 1]
Output
3

The first three panels answer in a row. The pair at the end is only two wide.

Example 2

Input
status = [0, 1, 0, 0, 1, 1, 1, 1]
Output
4

The stretch runs to the end of the row, so it still counts as four panels.

Example 3

Input
status = [0, 0]
Output
0

Nothing answered, so there is no stretch to measure.

Constraints

  • 1 <= status.length <= 10^5
  • status[i] is either 0 or 1.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def longest_online_run(status: list[int]) -> int:
Java
public int longestOnlineRun(int[] status)
September 7
Apply