Sort. Fix one index; two-sum the rest with two pointers. Skip duplicates.
Input
6 -1 0 1 2 -1 -4
Output
-1 -1 2 | -1 0 1
3 0 1 1