Practice 4Sum
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Return every distinct value quadruplet [nums[a], nums[b], nums[c], nums[d]] whose sum equals target. The four indices a, b, c and d must be different valid positions in nums. Different index choices yielding the same four values count as one quadruplet. Return the quadruplets in any order.
Source: 4Sum on LeetCode. Use the original task for its coding environment and submissions.
Examples
# 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]]
Constraints
1 <= nums.length <= 200
-10^9 <= nums[i] <= 10^9
-10^9 <= target <= 10^9
Related LeetCode Problems
Practice more problems similar to 4Sum.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.