#C5348. Longest Even Subarray
Longest Even Subarray
Longest Even Subarray
You are given an array of integers. Your task is to find the length of the longest contiguous subarray that contains only even numbers.
Formally, if the given array is \(A = [a_1, a_2, \dots, a_n]\), you should find the maximum length \(L\) such that there exists an index \(i\) with \(1 \le i \le n-L+1\) for which \(a_i, a_{i+1}, \dots, a_{i+L-1}\) are even. If no even number exists in the array, output 0.
Example: For the array [1, 2, 4, 6, 3, 8, 10, 12, 1, 2], the answer is 3 because the longest contiguous subarray of even numbers is [2, 4, 6].
inputFormat
The input consists of two lines:
- The first line contains a single integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output a single integer denoting the length of the longest contiguous subarray consisting entirely of even numbers.
## sample10
1 2 4 6 3 8 10 12 1 2
3
</p>