#K68727. Longest Balanced Odd-Even Subarray

    ID: 32929 Type: Default 1000ms 256MiB

Longest Balanced Odd-Even Subarray

Longest Balanced Odd-Even Subarray

Given an array of integers of length \( n \), find the length of the longest contiguous subarray in which the number of odd numbers is equal to the number of even numbers.

Input: The first line contains a single integer \( n \) denoting the number of elements in the array. The second line contains \( n \) space-separated integers representing the array elements.

Output: Print a single integer representing the length of the longest contiguous subarray where the count of odd and even numbers are equal. If no such subarray exists, output \( 0 \).

Note: A subarray is a contiguous segment of the array.

inputFormat

The input consists of two lines:

  • The first line contains one integer, \( n \) — the number of elements in the array.
  • The second line contains \( n \) integers separated by space.

outputFormat

Output a single integer representing the length of the longest contiguous subarray where the number of odd and even numbers are equal.

## sample
5
1 2 3 4 5
4