#C919. Zero Sum Triplet
Zero Sum Triplet
Zero Sum Triplet
You are given an array of integers. Your task is to determine whether there exists a triplet (three distinct elements) in the array whose sum is zero. In other words, check if there exist indices i, j, k with i < j < k such that
For each test case, print YES if such a triplet exists; otherwise, print NO.
inputFormat
The first line of input contains an integer T
, the number of test cases. Each test case consists of two lines. The first line of each test case contains an integer N
representing the size of the array. The second line contains N
space-separated integers representing the elements of the array.
Input Format:
T N a1 a2 ... aN ... (repeated T times)
outputFormat
For each test case, output a single line containing YES
if there is at least one triplet whose sum is zero, or NO
otherwise.
Output Format:
YES/NO (One per test case)## sample
2
5
-1 0 1 2 -1
5
1 2 3 4 5
YES
NO
</p>