#K44817. Triplets Sum Zero
Triplets Sum Zero
Triplets Sum Zero
Given an array of n integers, find all unique triplets (a, b, c) such that \(a+b+c=0\). Each triplet must be printed on a new line in the format "a b c", and the triplets should be presented in lexicographical order. If there is no valid triplet, output an empty string.
Note: The same set of numbers should not appear more than once in the output regardless of the order.
inputFormat
The first line of input contains an integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers. All input is read from stdin
.
outputFormat
Output each unique triplet in a new line with the three integers separated by a single space. The triplets must be listed in lexicographical order. If no triplet exists, print an empty string. The output is written to stdout
.## sample
5
-1 0 1 2 -1
-1 -1 2
-1 0 1
</p>