The problem. Given an array nums that contains only 0s and 1s, return the length of the longest subarray with as many 0s as 1s. If there is none, return 0. (On LeetCode this is Contiguous Array.)
nums = [1, 0, 1, 1, 1, 0, 0] -> 6 ([0, 1, 1, 1, 0, 0])
nums = [0, 0, 1, 1, 0] -> 4 ([0, 0, 1, 1] or [0, 1, 1, 0])
nums = [1, 1, 1] -> 0Members only · free account
The rest of this lesson, with 7 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson