#C901. 3Sum Problem
3Sum Problem
3Sum Problem
You are given an array of integers. Your task is to find all unique triplets ((a, b, c)) in the array such that they satisfy the equation $$a + b + c = 0$$. Each triplet must be output in non-decreasing order (i.e. (a \le b \le c)). The overall list of triplets can be printed in any order, but no duplicate triplets are allowed.
Note: Two triplets are considered the same if they contain the same three numbers regardless of order, so duplicate combinations should be avoided.
inputFormat
The input is read from standard input and has the following format:
- The first line contains an integer \(n\) denoting the number of elements.
- The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
Print each unique triplet in a separate line. Each triplet should consist of three space-separated integers in non-decreasing order. If no such triplet exists, do not print anything.## sample
6
-1 0 1 2 -1 -4
-1 -1 2
-1 0 1
</p>