#C11318. Unique Quadruplets Sum
Unique Quadruplets Sum
Unique Quadruplets Sum
Given an array of integers and a target integer \(X\), find all unique quadruplets in the array that sum up to \(X\). Each quadruplet should be sorted in non-decreasing order and the list of all quadruplets should be sorted lexicographically.
Constraints:
- \(1 \leq n \leq 100\), where \(n\) is the number of elements in the array.
- \(-10^9 \leq arr[i] \leq 10^9\) for each \(arr[i]\) in the array.
Example 1:
Input: 6 1 0 -1 0 -2 2 0</p>Output: [[-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]]
Example 2:
Input: 5 2 2 2 2 2 8</p>Output: [[2, 2, 2, 2]]
inputFormat
The input is given from \(stdin\) in the following format:
n arr[0] arr[1] ... arr[n-1] X
Where \(n\) is the number of elements, followed by \(n\) space-separated integers representing the array and an integer \(X\) representing the target sum.
outputFormat
Print to \(stdout\) the list of unique quadruplets (each quadruplet is a list of 4 integers) that sum up to \(X\). The output should exactly match the Python list representation.
## sample6
1 0 -1 0 -2 2
0
[[-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]]