Description
Given an array nums of n integers, return all unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that a, b, c, d are distinct indices and nums[a] + nums[b] + nums[c] + nums[d] == target. You may return the answer in any order.
Examples
Input:
nums = [1,0,-1,0,-2,2], target = 0Output:
[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]Explanation:
Three unique quadruplets sum to 0.
Input:
nums = [2,2,2,2,2], target = 8Output:
[[2,2,2,2]]Explanation:
Only one quadruplet exists.
Input:
nums = [-3,-1,0,2,4,5], target = 3Output:
[[-3,-1,2,5],[-3,0,2,4]]Explanation:
Two unique quadruplets sum to 3: [-3,-1,2,5] gives -3-1+2+5=3, and [-3,0,2,4] gives -3+0+2+4=3. This example demonstrates finding quadruplets with both negative and positive numbers where multiple valid combinations exist.
Constraints
- •
1 ≤ nums.length ≤ 200 - •
-10⁹ ≤ nums[i] ≤ 10⁹ - •
-10⁹ ≤ target ≤ 10⁹