Overview - Three Sum Problem All Unique Triplets
What is it?
Given an integer array, find all unique triplets (a, b, c) such that a + b + c = 0. No duplicate triplets should appear in the result. The optimal solution sorts the array, then uses a fixed pointer and two-pointer scan to find pairs that complete each triplet in O(n²) time.
Why it matters
Three Sum is a canonical two-pointer problem that extends Two Sum to three elements. It demonstrates how sorting enables O(n) pair-finding, how to skip duplicates without a hash set, and how the two-pointer technique reduces a potentially O(n³) brute-force to O(n²). In C, managing the result collection requires careful dynamic array or fixed-size array handling.
Where it fits
You need comfort with C arrays, sorting (qsort), and the two-pointer technique before tackling this. After mastering it, Four Sum, Three Sum Closest, and Container With Most Water follow naturally.
