#C7688. Maximum Consecutive Available Timeslots
Maximum Consecutive Available Timeslots
Maximum Consecutive Available Timeslots
You are given a series of timeslots represented by an array of integers. In this array, 0
denotes an available timeslot while 1
denotes a booked one. Your task is to determine the length of the longest contiguous segment of available timeslots.
Formally, given an array a of length n, you need to compute:
where the segment consists solely of zeros. If the array is empty or no available timeslot exists, the answer is 0
.
inputFormat
The input is given via standard input and consists of two parts:
- The first line contains an integer
n
representing the number of timeslots. - If
n > 0
, the second line containsn
space-separated integers (each either0
or1
), representing the timeslots.
If the array is empty, n
will be 0
and there will be no second line.
outputFormat
Output a single integer to standard output, which is the length of the longest contiguous segment of available timeslots.
## sample9
1 0 0 1 0 0 0 1 0
3