#K7636. Four Sum
Four Sum
Four Sum
Given an array of integers nums and an integer target, your task is to find all unique quadruplets \( [a, b, c, d] \) such that \( a + b + c + d = target \). Each quadruplet must be sorted in non-decreasing order, and the overall set of quadruplets should be output in lexicographical order. Duplicate quadruplets should not be included.
This problem requires an efficient solution, as a naive approach may lead to excessive time complexity. Consider using sorting along with multiple pointers to reduce the search space.
inputFormat
The input is provided via stdin in the following format:
- The first line contains an integer \( n \), representing the number of elements in the array.
- The second line contains \( n \) space-separated integers, which constitute the array nums.
- The third line contains an integer target.
outputFormat
Output the total count of unique quadruplets on the first line. Each of the following lines should contain one quadruplet: four space-separated integers in non-decreasing order. The quadruplets must be printed in lexicographical order.
## sample6
1 0 -1 0 -2 2
0
3
-2 -1 1 2
-2 0 0 2
-1 0 0 1
</p>