#C10146. Unique Quadruplets Sum

    ID: 39319 Type: Default 1000ms 256MiB

Unique Quadruplets Sum

Unique Quadruplets Sum

You are given an array of n integers and an integer target. Your task is to find all unique quadruplets \( [a, b, c, d] \) such that:

[ a + b + c + d = \text{target} ]

Each quadruplet must be in non-decreasing order, and the set of quadruplets should not contain duplicates.

Note: Two quadruplets are considered different if at least one corresponding element is different. Use efficient algorithms (e.g., sorting and two-pointer techniques) to achieve an acceptable time complexity.

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  • The first line contains an integer \( n \), the number of elements in the array.
  • The second line contains \( n \) space-separated integers representing the array elements.
  • The third line contains the target integer.

outputFormat

Print each unique quadruplet in a separate line to standard output (stdout). Within each line, print the four integers in the quadruplet separated by a single space. The quadruplets must be printed in lexicographical order. If there are no quadruplets that sum to the target, produce no output.

## sample
6
1 0 -1 0 -2 2
0
-2 -1 1 2

-2 0 0 2 -1 0 0 1

</p>