#C6714. Longest Contiguous Subarray with Equal Number of 0s and 1s

    ID: 50505 Type: Default 1000ms 256MiB

Longest Contiguous Subarray with Equal Number of 0s and 1s

Longest Contiguous Subarray with Equal Number of 0s and 1s

You are given an array consisting of only 0s and 1s. Your task is to find the length of the longest contiguous subarray that has an equal number of 0s and 1s.

Hint: Use a hashmap to keep track of the difference between the count of 1s and 0s as you iterate through the array. When the same difference is seen again, it means the subarray between the previous index and the current index has equal numbers of 0s and 1s.

inputFormat

The input is given via standard input (stdin) and contains two lines. 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 either 0 or 1) representing the array elements.

outputFormat

Output via standard output (stdout) a single integer representing the length of the longest contiguous subarray that contains an equal number of 0s and 1s.

## sample
7
0 1 0 1 0 1 1
6

</p>