#C3261. Longest Consecutive Active Streak

    ID: 46669 Type: Default 1000ms 256MiB

Longest Consecutive Active Streak

Longest Consecutive Active Streak

You are given a binary array that represents the status of a system over a period of time, where a value of 1 indicates an active status and 0 indicates an inactive status. Your task is to compute the length of the longest consecutive sequence of active statuses.

For example, if the array is [1, 1, 0, 1, 1, 1, 0, 0, 1, 1], the longest consecutive sequence of 1s is 3.

In mathematical terms, given an array (A = [a_1, a_2, \dots, a_n]) with (a_i \in {0,1}), find the maximum (k) such that there exists an index (i) with (a_i = a_{i+1} = \dots = a_{i+k-1} = 1).

inputFormat

The first line of input contains an integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers (each either 0 or 1) representing the status of each time unit.

outputFormat

Output a single integer representing the length of the longest consecutive sequence of active statuses (1s) found in the array.## sample

10
1 1 0 1 1 1 0 0 1 1
3