You are given an integer array nums.

A subarray is called balanced if the number of distinct even numbers in the subarray is equal to the number of distinct odd numbers.

Return the length of the longest balanced subarray.

 

Example 1:

Input: nums = [2,5,4,3]

Output: 4

Explanation:

Example 2:

Input: nums = [3,2,2,5,4]

Output: 5

Explanation:

Example 3:

Input: nums = [1,2,3,2]

Output: 3

Explanation:

 

Constraints: