#C11936. Three Sum Problem
Three Sum Problem
Three Sum Problem
Given an array of integers, find all unique triplets in the array that sum to zero. For any triplet \( (a, b, c) \), they must satisfy the equation: \( a + b + c = 0 \). Each triplet must be in non-decreasing order and the overall list of triplets should be sorted in lexicographical order. Duplicate triplets are not allowed.
inputFormat
The input consists of two lines. The first line contains a single integer \( n \) which denotes the size of the array. The second line contains \( n \) space-separated integers representing the elements of the array.
outputFormat
The output should start with a line containing a single integer \( k \), the number of unique triplets found. Each of the following \( k \) lines should contain one triplet: three space-separated integers in non-decreasing order. The triplets must be printed in lexicographical order. If no triplets are found, output just a single line with the number 0.
## sample6
-1 0 1 2 -1 -4
2
-1 -1 2
-1 0 1
</p>