#K44727. Longest Even-Odd Subarray
Longest Even-Odd Subarray
Longest Even-Odd Subarray
You are given an array of integers. Your task is to determine the length of the longest contiguous subarray that contains an equal number of even and odd numbers.
Formally, given an array \(A\) of length \(n\), find the maximum integer \(L\) for which there exists a subarray \(A[i\ldots j]\) (with \(j - i + 1 = L\)) such that the number of even integers is equal to the number of odd integers.
Example: For the array [1, 2, 3, 4, 5, 6], the entire array is valid as it contains three even numbers (2, 4, 6) and three odd numbers (1, 3, 5), so the answer is 6.
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 representing the elements of the array.
\(1 \leq n \leq 10^5\) and each element can be any integer.
outputFormat
Output a single integer: the length of the longest contiguous subarray that contains an equal number of even and odd numbers.
## sample6
1 2 3 4 5 6
6
</p>