3Sum
mediumFind all unique triplets that sum to zero
3Sum
Key Insight
Sort first. Fix one element, use two pointers for remaining two. Skip duplicates.
Step 1Sort Array
Sorted for two-pointer
-4
0-1
1-1
20
31
42
5[-1, 0, 1, 2, -1, -4] → [-4, -1, -1, 0, 1, 2]
1 / 5