#K1496. Longest Contiguous Ones Subarray

    ID: 24250 Type: Default 1000ms 256MiB

Longest Contiguous Ones Subarray

Longest Contiguous Ones Subarray

You are given an array of integers consisting only of 0s and 1s. Your task is to find the length of the longest contiguous subarray that contains only 1s.

For example, given the array [1, 1, 0, 1, 1, 1], the longest subarray of consecutive ones is of length 3.

The problem can be mathematically described as: Given an array \(A\) of size \(n\) where \(A_i \in \{0,1\}\), determine \(\max_{i \leq j} \{j - i + 1 \mid A_i = A_{i+1} = \cdots = A_j = 1\}\). If there are no 1s, the answer is 0.

inputFormat

The first line of input contains a single integer \(n\) which denotes the number of elements in the array. The second line contains \(n\) space-separated integers (each either 0 or 1) representing the elements of the array.

outputFormat

Output a single integer representing the length of the longest contiguous subarray of 1s.

## sample
6
1 1 0 1 1 1
3