#K44367. Find Unique Quadruplets That Sum to Target
Find Unique Quadruplets That Sum to Target
Find Unique Quadruplets That Sum to Target
Given an array of integers and a target integer ( k ), your task is to find all unique quadruplets ( [a, b, c, d] ) such that ( a + b + c + d = k ).
The quadruplets must be output in lexicographical order. Each quadruplet should be printed on a separate line with its elements separated by a single space. Duplicate quadruplets (i.e. quadruplets with the same elements in the same order) must not be included in the output.
Note: The input is given through standard input, and the output should be written to standard output. If no quadruplets exist that satisfy the condition, output []
.
inputFormat
The first line contains two integers ( n ) and ( k ), where ( n ) is the number of elements in the array and ( k ) is the target sum. The second line contains ( n ) space-separated integers representing the array elements.
outputFormat
If one or more quadruplets are found, output each quadruplet on a new line with its four integers separated by a single space, in lexicographical order. If no quadruplet is found, output []
.## sample
6 0
1 0 -1 0 -2 2
-2 -1 1 2
-2 0 0 2
-1 0 0 1
</p>