#K4946. Three Sum Zero
Three Sum Zero
Three Sum Zero
Given a list of integers, determine whether there exist three distinct elements whose sum is zero. In other words, find three different indices (i, j, k) such that (a_i + a_j + a_k = 0). If such a triplet exists, print YES; otherwise, print NO. This problem tests your ability to implement efficient algorithms, such as sorting combined with a two-pointer technique, to find the answer with a time complexity better than (O(n^3)).
inputFormat
The input consists of two lines. The first line contains a single integer (n) representing the number of elements in the list. The second line contains (n) space-separated integers.
outputFormat
Output a single line: either YES if there exists a triplet of elements that add up to zero, or NO if no such triplet exists.## sample
5
-1 2 1 -4 2
YES