#K12801. Unique Zero Sum Triplets
Unique Zero Sum Triplets
Unique Zero Sum Triplets
You are given an array of ( n ) integers. Your task is to determine the number of unique triplets ( (i, j, k) ) such that ( i<j<k ) and ( a_i + a_j + a_k = 0 ). Two triplets are considered the same if they contain the same set of numbers.
For example, given the array [-1, 0, 1, 2, -1, -4], there are exactly 2 unique triplets that sum to zero: ( (-1, -1, 2) ) and ( (-1, 0, 1) ).
inputFormat
The input is given via standard input (stdin). The first line contains a single integer ( n ), representing the number of elements in the array. The second line contains ( n ) space-separated integers.
outputFormat
Output a single integer to standard output (stdout) representing the number of unique triplets whose sum is zero.## sample
6
-1 0 1 2 -1 -4
2
</p>