#K13271. Unique Quadruplets Sum
Unique Quadruplets Sum
Unique Quadruplets Sum
In this problem, you are given an array of integers and an integer target. Your task is to find all unique quadruplets (i.e. four numbers) (a_i, a_j, a_k, a_l) such that their sum is equal to the target, i.e., [ a_i + a_j + a_k + a_l = target ]
A quadruplet is considered unique if no other quadruplet contains the same set of numbers, regardless of order. The output quadruplets should be printed in lexicographical order and each quadruplet must have its elements in non-decreasing order.
If there are no quadruplets that satisfy the condition, print a single line with exactly: []
.
inputFormat
The input is given via standard input (stdin) and consists of three lines:
- The first line contains an integer (n), representing the number of elements in the array.
- The second line contains (n) space-separated integers, representing the elements of the array.
- The third line contains an integer, representing the target sum.
It is guaranteed that (n \ge 4).
outputFormat
Print the unique quadruplets in lexicographical order, each quadruplet on a new line. A quadruplet consists of 4 space-separated integers in non-decreasing order. If no quadruplets can be found, output a single line containing exactly: []## sample
6
1 0 -1 0 -2 2
0
-2 -1 1 2
-2 0 0 2
-1 0 0 1
</p>