Given an array arr of 0s and 1s. Find and return the length of the longest subarray with equal number of 0s and 1s.
Example 1
Input: arr[] = [1, 0, 1, 1, 1, 0, 0]
Output: 6
Explanation: arr[1...6] is the longest subarray with three 0s and three 1s.
Example 2
Input: arr[] = [0, 0, 1, 1, 0]
Output: 4 Explnation: arr[0...3] or arr[1...4] is the longest subarray with two 0s and two 1s.
Example 3
Input: arr[] = [0]
Output: 0 Explnation: There is no subarray with an equal number of 0s and 1s.
Sign in to write, run, and submit your solution against the full test suite.