#K4321. Longest Zero Sum Subarray
Longest Zero Sum Subarray
Longest Zero Sum Subarray
You are given an array of integers. Your task is to find the length of the longest contiguous subarray whose sum is equal to 0.
For example, given the array \(A = [15, -2, 2, -8, 1, 7, 10, 23]\), the longest subarray with sum 0 is of length 5.
The solution requires efficient handling of cumulative sums and the use of hashing techniques to remember previously seen sums. If an accumulated sum is seen again, it indicates that the elements between these occurrences sum to 0.
Note: The sum and indices are handled using standard integer arithmetic. In cases where the array is empty, the answer is 0.
inputFormat
The input is read from standard input (stdin) and has the following format:
T n_1 A_1[0] A_1[1] ... A_1[n_1-1] ... n_T A_T[0] A_T[1] ... A_T[n_T-1]
Here, \(T\) is the number of test cases. For each test case, the first line contains an integer \(n\) denoting the size of the array, and the following line contains \(n\) space-separated integers which represent the array \(A\).
outputFormat
For each test case, output a single integer on a new line which is the length of the longest contiguous subarray with sum equal to 0. The output is printed to standard output (stdout).
## sample1
8
15 -2 2 -8 1 7 10 23
5
</p>