
Contiguous Array (medium)
Problem Statement
Given an array nums containing only 1 and 0 digits, return the maximum length of the contiguous subarray having an equal number of 1 and 0.
Examples
- Example 1:
- Input:
[0, 1] - Expected Output:
2 - Justification: The longest subarray with equal numbers of 0s and 1s is [0, 1].
- Input:
- Example 2:
- Input:
[1, 1, 0, 0, 1, 1, 0] - Expected Output:
6 - Justification: The subarray [1, 0, 0, 1, 1, 0] contains three 0s and three 1s.
- Input:
- Example 3:
- Input:
[0, 1, 1, 0, 1, 0, 0, 1, 1] - Expected Output:
8 - Justification: The subarray from the first to the eighth element is the longest with an equal number of 0s and 1s.
- Input:
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory