#C3493. Three Sum Problem
Three Sum Problem
Three Sum Problem
You are given an array of n integers. Your task is to find all unique triplets (a, b, c) in the array such that their sum is zero, i.e., \(a+b+c=0\). Two triplets are considered the same if they contain the same three numbers regardless of their order.
For example, for the array [-1, 0, 1, 2, -1, -4], the unique triplets would be [-1, -1, 2] and [-1, 0, 1]. The order of output does not matter, but within each triplet, the numbers should be in non-decreasing order.
inputFormat
The input is given via standard input and consists of two lines:
- 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 all unique triplets, each on a separate line, where the numbers within a triplet are in non-decreasing order. The triplets themselves should be sorted in lexicographical order. If there are no such triplets, output the line "No triplets found".
## sample6
-1 0 1 2 -1 -4
-1 -1 2
-1 0 1
</p>