#C5696. Three Sum Triplets
Three Sum Triplets
Three Sum Triplets
You are given an array of integers. Your task is to find all unique triplets \( (a, b, c) \) such that \( a+b+c=0 \). Each triplet must be output in non-decreasing order (i.e. \( a \le b \le c \)). If there are multiple triplets, print each triplet in a separate line with the numbers separated by a single space. If no such triplet exists, output No Triplets Found
.
Note: Two triplets are considered the same if they consist of the same three numbers, regardless of order. The expected time complexity is better than \(O(n^3)\) for each test case.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer \(T\) representing the number of test cases.
- For each test case:
- The first line contains an integer \(N\) denoting the number of elements in the array.
- The second line contains \(N\) space-separated integers.
outputFormat
For each test case, output the list of unique triplets that sum to zero. For a test case:
- If at least one triplet is found, print each triplet on a separate line (numbers separated by a single space).
- If no triplets are found, print
No Triplets Found
.
If there are multiple test cases, separate the outputs of consecutive test cases with an empty line.
## sample1
3
0 0 0
0 0 0
</p>