Neural Mastery
← Back to Practice

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.

Implement it yourself
assert three_sum_zero([-1, 0, 1, 2, -1, -4]) == [[-1, -1, 2], [-1, 0, 1]] assert three_sum_zero([1, 2, 3]) == [] assert three_sum_zero([0, 0, 0, 0]) == [[0, 0, 0]] assert three_sum_zero([]) == []

Next: Minimum Window Substring

Last updated Sep 5, 2026Edit this pageReport an issue