Max Consecutive Ones
Real-world version: Longest Online Panel RunThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def longest_online_run(status: list[int]) -> int:public int longestOnlineRun(int[] status)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 9 test cases: 9 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's