#K70322. Longest Contiguous Subarray with Zero Sum
Longest Contiguous Subarray with Zero Sum
Longest Contiguous Subarray with Zero Sum
You are given an array of integers. Your task is to determine the length of the longest contiguous subarray whose sum is equal to 0.
More formally, given an array \(a\) of length \(n\), find the maximum length \(L\) such that there exist indices \(i\) and \(j\) (with \(0 \leq i \leq j < n\)) where
\(\sum_{k=i}^{j} a[k] = 0\)
If no such subarray exists, output 0.
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, representing the elements of the array.
outputFormat
Output a single integer, the length of the longest contiguous subarray that sums to 0.## sample
7
1 -1 3 2 -2 -2 4
5
</p>