#C842. Three Sum Zero Triplets
Three Sum Zero Triplets
Three Sum Zero Triplets
You are given a list of integers. Your task is to determine whether there exist three distinct elements in the list whose sum is equal to (0). More formally, given an array (A) of (n) integers, check if there exist indices (i, j, k) (with (i \neq j \neq k)) such that:
[ A[i] + A[j] + A[k] = 0 ]
If such a triplet exists, print YES; otherwise, print NO.
Input is given via standard input (stdin) and output must be printed to standard output (stdout).
inputFormat
The first line contains a single integer (n) ((3 \le n \le 10^5)), the number of elements in the array. The second line contains (n) space-separated integers representing the array (A).
outputFormat
Output a single line containing YES if there exists a triplet of distinct indices (i, j, k) such that (A[i] + A[j] + A[k]=0); otherwise, output NO.## sample
5
-1 0 1 2 -1
YES