Problem
Longest Equal Binary Subarray
Learn this problemProblem statement
You are given a binary array arr containing only 0s and 1s.
Return the length of the longest contiguous subarray that contains an equal number of 0s and 1s.
Function
longestEqualBinarySubarray(arr: int[]) → intExamples
Example 1
arr = [0,1,0,0,1,1,0]return = 6The subarray [1,0,0,1,1,0] has three 0s and three 1s.
Example 2
arr = [0,0,1,1]return = 4The entire array is balanced.
Example 3
arr = [1,1,1]return = 0No non-empty subarray has an equal number of 0s and 1s.
Constraints
1 <= arr.length <= 100000arr[i]is either0or1