Three Sum to Zero
Difficulty: Medium · Pattern: Two Pointers · Concept: General Coding (DSA) — Core Patterns to Drill
A harder variant of Pair With Target Sum: instead of finding one pair that sums to a target, find every unique triplet in the array that sums to 0. The two-pointer trick still does the inner work, but now it has to run once per candidate anchor element, and — since the input isn't guaranteed distinct — duplicate triplets have to be actively suppressed, not just tolerated.
Your task: implement three_sum_zero(nums), returning a list of triplets [a, b, c] with a <= b <= c, no duplicate triplets, in any order relative to each other.
Next: Minimum Window Substring