v69806c1
Search for a command to run...
You are given a binary array nums consisting of only 0s and 1s.
Your task is to find the length of the longest contiguous subarray that contains an equal number of 0s and 1s.
If no such subarray exists, return 0.
This problem requires an efficient approach as brute force will not pass for large inputs.
[nums]
Example: [0,1,0,1,1,0,0]
Integer (length of longest valid subarray)
1 ≤ N ≤ 200000
nums[i] ∈ {0,1}
Expected Time Complexity: O(N)
Example 1
[0,1,0,1,1,0,0]
6
Example 2
[0,1,1,0,1,0,0,1,1]
8
Example 3
[0,1]
2