List Every Unique Quadruplet That Sums to a Target

Implement quadrupletsSummingToTarget

Given an integer array nums and an integer target, find every combination of four different elements whose values add up to target, and report them with no duplicate quadruplet appearing twice — a quadruplet is a duplicate of another if it has the same four values, regardless of which indices produced them. Since the answer is checked as a single flat list of numbers, package your result the same way as the triplet version: sort the four values inside each quadruplet from smallest to largest, then arrange the quadruplets themselves from smallest to largest (comparing their first value, then second, then third, then fourth), and concatenate everything into one array.

Example 1:

Input: nums = [2,-1,0,3,-3,1], target = 2

Output: [-3,0,2,3,-1,0,1,2]

Example 2:

Input: nums = [0,0,0,0], target = 0

Output: [0,0,0,0]

Example 3:

Input: nums = [1,2,3,4], target = 100

Output: []

+ 4 hidden test cases run on Submit.

Constraints:

  • 4 ≤ nums.length ≤ 200
  • -10⁵ ≤ nums[i] ≤ 10⁵
  • -10⁵ ≤ target ≤ 10⁵

nums =

[2, -1, 0, 3, -3, 1]

target =

2