Longest Equal-Zero-One Subarray
Problem statement
Given a binary array nums, return the maximum length of a contiguous subarray containing the same number of 0s and 1s.
Function
longestBalancedSubarray(nums: int[]) → intExamples
Example 1
nums = [0,1]return = 2The full array contains one zero and one one.
Example 2
nums = [0,1,0]return = 2Either length-two prefix is balanced.
Constraints
0 <= nums.length <= 100000.- Every value is
0or1.