#C9417. Longest Even-Odd Subarray
Longest Even-Odd Subarray
Longest Even-Odd Subarray
You are given an array of integers. Your task is to find the length of the longest contiguous subarray in which the number of even and odd integers are equal. If no such subarray exists, output 0.
For example, consider the array \( [1, 2, 3, 4, 5] \). One such subarray is \( [2, 3, 4, 5] \) because it contains two even numbers (2 and 4) and two odd numbers (3 and 5), making its length 4.
Hint: Transform the array by converting even numbers to \( +1 \) and odd numbers to \( -1 \). Then, find the longest subarray whose sum is 0.
inputFormat
The first line of input contains a single integer ( T ), representing the number of test cases. For each test case, the first line contains an integer ( N ) (the number of elements in the array). The next line contains ( N ) space-separated integers representing the array.
outputFormat
For each test case, output a single line containing the length of the longest contiguous subarray that has an equal number of even and odd integers.## sample
1
5
1 2 3 4 5
4