#C14421. Longest Contiguous Subarray with Equal 0s and 1s
Longest Contiguous Subarray with Equal 0s and 1s
Longest Contiguous Subarray with Equal 0s and 1s
You are given an array consisting only of 0s and 1s. Your task is to determine the length of the longest contiguous subarray that contains an equal number of 0s and 1s. If no such subarray exists, output 0.
The problem requires you to read input from standard input (stdin) and write the result to standard output (stdout). The input starts with an integer n, indicating the number of elements in the array, followed by n space-separated integers (each either 0 or 1).
Solve the problem with an efficient algorithm so that it can handle large arrays within reasonable time limits.
inputFormat
The first line contains a single integer n representing the number of elements in the array. The second line contains n space-separated integers, each being either 0 or 1.
outputFormat
Output a single integer which is the length of the longest contiguous subarray with an equal number of 0s and 1s. If no such subarray exists, output 0.
## sample2
0 1
2
</p>