#K51617. Zero Sum Subarray Detection
Zero Sum Subarray Detection
Zero Sum Subarray Detection
In this problem, you are given an array of integers and you must determine whether there exists a continuous subarray whose sum is zero. More formally, for an array \(A\) of size \(n\), you need to check if there exist indices \(i\) and \(j\) (with \(i < j\)) such that
[ A[i] + A[i+1] + \cdots + A[j] = 0 ]
To solve this problem efficiently, you can use a cumulative sum approach with an appropriate data structure to store intermediate sums. This technique allows you to detect if a cumulative sum repeats (or becomes zero), which would indicate the existence of a zero sum subarray.
inputFormat
The first line contains the integer (T), the number of test cases. For each test case, the first line contains an integer (n) denoting the number of elements. The second line contains (n) space-separated integers representing the array.
outputFormat
For each test case, output a single line with "Yes" if there exists any continuous subarray whose sum is zero, or "No" otherwise.## sample
4
6
4 2 -3 1 6
5
4 2 0 1 6
5
4 2 3 1 6
5
0 1 2 3 4
Yes
Yes
No
Yes
</p>