#K47602. Zero Subarray Sum
Zero Subarray Sum
Zero Subarray Sum
You are given an array of integers. Your task is to determine whether there exists a contiguous subarray whose sum is zero. A contiguous subarray is defined by a segment (a[l], a[l+1], \ldots, a[r]) (with (1 \le l \le r \le n)) and its sum is given by (\sum_{i=l}^{r} a_i). If such a subarray exists, print "YES"; otherwise, print "NO". This problem can be solved efficiently using the prefix sums technique.
inputFormat
Input is read from standard input (stdin). The first line contains an integer (T) representing the number of test cases. Each test case consists of two lines: the first line contains an integer (n) (the number of elements in the array), and the second line contains (n) space-separated integers.
outputFormat
For each test case, output a single line to standard output (stdout) containing either "YES" if a contiguous subarray with sum zero exists, or "NO" otherwise.## sample
3
5
1 2 -3 4 5
4
-1 1 -1 1
3
2 3 9
YES
YES
NO
</p>