Contiguous Array
Medium
LC #525
prefix sumhash mapNot attempted yet
Given a binary array nums (only 0s and 1s), return the
length of the longest contiguous subarray that contains
the same number of 0s and 1s. Return 0 if there is
none.
Example 1
Input: nums = [0, 1]
Output: 2
Example 2
Input: nums = [0, 1, 0]
Output: 2
Either [0, 1] or [1, 0].
Example 3
Input: nums = [0, 1, 1, 1, 1, 1, 0, 0, 0]
Output: 6
[1, 1, 1, 0, 0, 0] has three of each.
Constraints
- 1 ≤ len(nums) ≤ 10⁵
- nums[i] is 0 or 1