Skip to content
CampusEduX

Subarray with Equal 0s and 1s

Mediumjavapythonccppjavascript

Given a binary array containing only 0 and 1, find the length of the longest contiguous subarray with an equal number of zeros and ones.

Input Format

The first line contains an integer N. The second line contains N space-separated integers, each 0 or 1.

Output Format

Print the maximum length, or 0 if no such subarray exists.

Related Problems

  • Zero Sum Subarray
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Longest Subarray with Sum K
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Longest Consecutive Sequence
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...