Contiguous Array Equal Zeros Ones Problem

Contiguous Array Equal Zeros Ones Problem — ExecCode Easy DSA Practice

Solve the Contiguous Array Equal Zeros Ones problem on ExecCode. Free online easy DSA practice in Hashing. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given a binary array nums containing only 0s and 1s, find the maximum length of a contiguous subarray that contains an equal number of 0s and 1s.

Examples

Input nums = [0, 1, 0, 1, 0, 1]; Output 6. Input nums = [0, 1]; Output 2. Input nums = [0, 0, 1, 1, 0]; Output 4

Constraints

1 ≤ nums.length ≤ 10⁵ nums[i] is either 0 or 1

Practice Contiguous Array Equal Zeros Ones free on ExecCode. Browse DSA problems, topic map, and placement guides.