#K78327. Longest Green Light Segment
Longest Green Light Segment
Longest Green Light Segment
Given a sequence of n traffic lights, each represented by an integer (where 1
indicates a green light and 0
indicates any other color), your task is to determine the length of the longest contiguous segment of green lights. In other words, find the maximum length of consecutive 1
s in the sequence.
You can mathematically express the solution as:
$$\max_{\text{segment}}\{\text{length of consecutive ones}\}$$
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains a single integer
n
, representing the number of traffic lights. - The second line contains
n
space-separated integers (each either0
or1
), representing the state of each traffic light.
outputFormat
Output a single integer to standard output (stdout), which is the length of the longest segment of consecutive green lights.
## sample10
1 1 0 1 1 1 0 0 1 1
3