#3721

Longest Balanced Subarray II

hard · 33.7% accepted · 336 likes · top 11%

array · hash table · divide and conquer · segment tree · prefix sum

Description

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.

Solution