⚡ AlgoZen_

3Sum

Intermediate

Find all unique triplets that sum to zero. Sort the array, fix one element, then use two pointers on the rest. Carefully skip duplicates.

time:O(n²)
space:O(1)
⚡ +200_XP
step[1/20]
> Start
-4
-1
-1
0
1
2
Find all unique triplets in [-4, -1, -1, 0, 1, 2] that sum to 0. Sort first, then fix one element and two-pointer the rest.

// tap NEXT STEP to walk through one step at a time