insidcode
ProblemsDuelLeaderboardStats
Sign In
  1. Home
  2. Problems
  3. Find the length of the longest contiguous subarray with an equal count of 0s and 1s.

Find the length of the longest contiguous subarray with an equal count of 0s and 1s.

Difficulty: Hard

Phase: 6 · Mixed Logical Challenges

XP Reward: 30 XP

Topics: Mixed Logical Challenges, Hard

Supported Languages: Python, JavaScript, C, C++, Java

Problem Description

Given binary array containing 0s and 1s, find the maximum length of a contiguous subarray with an equal number of 0s and 1s. Input Format: Read input from standard input (stdin). Output Format: Print the result to standard output (stdout).

Constraints

  • -10^9 <= N <= 10^9

Examples

Example 1

Input: 4 0 1 0 1

Output: 4

Explanation: Sample execution for input 4 0 1 0 1