4Sum
Find all unique quadruplets in the array which gives the sum of target.

30:00

4Sum
medium
Topics
Companies

Find all unique quadruplets in the array which gives the sum of target.

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]]
Constraints:
  • 1nums.length2001 \leq \text{nums.length} \leq 200

  • 109nums[i]109-10^9 \leq \text{nums}[i] \leq 10^9

  • 109target109-10^9 \leq \text{target} \leq 10^9

Input
arr ={"nums":[1,0,-1,0,-2,2],"target":0}
Status

Start 4Sum

Target
0
Current Sum

?

Sorted Array
1

0

0

1

-1

2

0

3

-2

4

2

5

i (first)
j (second)
L/R (two pointers)
Found
Found Quadruplets (0)
No quadruplets found yet
Variables
VariableValue
target0
DepthFunction Call
Stack empty
0/41