#3719

Longest Balanced Subarray I

medium · 65.7% accepted · 479 likes · top 71%

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