#K86422. Longest Even-Odd Balanced Subarray

    ID: 36861 Type: Default 1000ms 256MiB

Longest Even-Odd Balanced Subarray

Longest Even-Odd Balanced Subarray

Given T test cases, each containing an integer N and an array A of N integers, your task is to find the length of the longest contiguous subarray where the number of even and odd integers are equal.

More formally, for an array \(A\) of length \(N\), find the maximum length \(L\) such that there exists indices \(i\) and \(j\) with \(0 \leq i < j \leq N\) and the subarray \(A[i \ldots j]\) contains an equal number of even and odd numbers. If no such subarray exists, output 0.

Input is given from STDIN and output should be written to STDOUT. Each test case is processed separately, and the answer for each case should be printed on a new line.

inputFormat

The first line contains an integer \(T\), the number of test cases. For each test case:

  • The first line contains an integer \(N\), the number of elements in the array.
  • The second line contains \(N\) space-separated integers representing the elements of the array \(A\).

outputFormat

For each test case, output a single integer on a new line representing the length of the longest contiguous subarray with an equal number of even and odd integers. If no such subarray exists, output 0.

## sample
3
6
1 2 3 4 5 6
3
1 2 3
4
2 4 6 8
6

2 0

</p>