Medium
Quiz
#18 4Sum
APPROACH
From array nums of n integers, find every unique quadruplet [nums[a], nums[b], nums[c], nums[d]] where all four indices are distinct, 0 <= a, b, c, d < n, and the four values sum to target. Results may appear in any order.
Example 1:
Input: nums = [1,0,-1,0,-2,2], target = 0
Output: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]
Example 2:
Input: nums = [2,2,2,2,2], target = 8
Output: [[2,2,2,2]]
1 of 4
1:00
What is the optimal approach for this problem?