4Sum
Given an integer array nums and an integer target, return all unique quadruplets [nums[a], nums[b], nums[c], nums[d]] with distinct indices such that the four values sum to target. The result must not contain duplicate quadruplets.
Open official problem prompt ↗List every distinct group of four values that add up to the given target, with no repeated group.
Like 3Sum with an extra locked digit on a combination padlock: you fix the first two dials, then spin the last two from opposite ends until the whole combination matches the target.
- Input
- nums = [1, 0, -1, 0, -2, 2], target = 0
- Output
- [[-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]]
- Why
- Each listed quadruplet sums to 0, and these are the only distinct value-combinations that do so.
1 <= nums.length <= 200-10^9 <= nums[i] <= 10^9-10^9 <= target <= 10^9