30:00
Given a binary array nums, return the maximum length of a contiguous subarray that contains an equal number of 0s and 1s.
1≤nums.length≤1051 \leq \text{nums.length} \leq 10^51≤nums.length≤105
nums[i]\text{nums}[i]nums[i] is either 000 or 111.
Run code to see results.
Treat every 1 as a step up and every 0 as a step down. The walk starts at height 0 before index 0, so record height 0 at index -1.
the walk: 1 steps up, 0 steps down
● first visit to a height
- - same height again = balanced run
▬ best run
nums
first index of each height
Given an array of 0s and 1s, find the length of the longest contiguous subarray that has the same number of 0s and 1s. Return 0 if there is none.