Loading problem…
This problem builds on three-sum. Complete that first, then load your solution to continue.
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 < na, b, c, and d are distinctnums[a] + nums[b] + nums[c] + nums[d] == targetYou may return the answer in any order.
Extend the 3Sum pattern to find all unique quadruplets that sum to a given target. This requires an additional layer of iteration over the two-pointer technique.
fourSum([1, 0, -1, 0, -2, 2], 0);
// [[-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]]
fourSum([2, 2, 2, 2, 2], 8);
// [[2, 2, 2, 2]]