coding•DSA & Problem Solving•Arrays & Two Pointers
4Sum Target Quadruplets
Problem Statement
Given an array `nums` of `n` integers, return an array of all the **unique** quadruplets `[nums[a], nums[b], nums[c], nums[d]]` such that:
- `0 <= a, b, c, d < n`
- `a`, `b`, `c`, and `d` are **distinct**.
- `nums[a] + nums[b] + nums[c] + nums[d] == target`
You may return the answer in **any order**.
### Constraints
- `1 <= nums.length <= 200`
- `-10^9 <= nums[i] <= 10^9`
- `-10^9 <= target <= 10^9`
### Input Format
First line contains the target integer.
Second line contains space-separated integers representing `nums`.
### Output Format
Print each unique quadruplet on a new line with space-separated numbers sorted ascendingly (quadruplets sorted lexicographically).
Sample Cases
Example 1Sample Case
Input: 0
1 0 -1 0 -2 2
Output: -2 -1 1 2
-2 0 0 2
-1 0 0 1
Example 2Sample Case
Input: 8
2 2 2 2 2
Output: 2 2 2 2
Example 3Sample Case
Input: 0
1
Output:
Example 4Sample Case
Input: 0
0
Output:
Constraints
Runtime Limit: 2000 ms per test batch
Memory Limit: 256 MB
Standard I/O stream reading
Official submissions are evaluated against hidden test cases on the server to verify time & memory complexity.