#K86272. Subset Sum Zero
Subset Sum Zero
Subset Sum Zero
Given an array of integers, determine if there exists a non-empty subset whose sum is zero. A subset is defined as any selection of elements from the array. You should output YES
if such a subset exists, or NO
otherwise.
For example, for the array [1, 2, -3, 4]
, one valid subset is [1, 2, -3]
whose sum equals 0. Therefore, the answer is YES
.
Note: The input will consist of multiple test cases. For each test case, you will be given the array size followed by the list of integers.
inputFormat
The first line contains an integer T denoting 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.
- The second line contains N space-separated integers.
outputFormat
For each test case, output a single line containing YES
if there exists a non-empty subset whose sum is zero, or NO
otherwise.
3
4
1 2 -3 4
5
1 3 -2 5 -6
3
1 2 3
YES
YES
NO
</p>