#C1381. Maximum Length Zero Sum Subarray

    ID: 43389 Type: Default 1000ms 256MiB

Maximum Length Zero Sum Subarray

Maximum Length Zero Sum Subarray

You are given an array of integers that may contain both positive and negative numbers. Your task is to find the length of the longest contiguous subarray whose sum equals zero.

Let \(S[i]\) denote the prefix sum up to index \(i\) (0-indexed), i.e., \(S[i] = arr[0] + arr[1] + \cdots + arr[i]\). A subarray from index \(a\) to \(b\) has a zero sum if \(S[b] - S[a-1] = 0\) (with the convention that \(S[-1] = 0\)).

Implement an efficient solution that reads the array from the standard input and prints the length of the largest contiguous subarray with a sum of zero to the standard output.

inputFormat

The first line contains a single integer \(n\) denoting the number of elements in the array. The second line contains \(n\) space-separated integers representing the array elements.

outputFormat

Output a single integer that is the length of the longest contiguous subarray whose sum is zero.

## sample
8
15 -2 2 -8 1 7 10 23
5