NumPy allowed · plain Python earns 10 bonus points
Reduce an O(n^3) triplet search to O(n^2) by sorting and pairing an outer loop with two-pointer search, deduplicating elements cleanly.
Implement three_sum(nums): find all unique triplets [a, b, c] that sum to zero. Return triplets sorted ascending, with the overall list of triplets sorted lexicographically.
three_sum(nums: list[int]) -> list[list[int]]