Three Number Zero Groups
Preview mode. Log in to edit, run, submit, and save progress.
Medium
Three Number Zero Groups
You are given an array of integers. Find all unique groups of three numbers whose sum is exactly 0. Each group must be returned in non-decreasing order, and the full answer must be sorted lexicographically. If no such group exists, return an empty list.
Examples
Example 1
Input:
-1 0 1 2 -1 -4
Output:
-1 -1 2
Explanation: The unique triplets that sum to 0 are [-1, -1, 2] and [-1, 0, 1].
Approach hint
Sort the array first so duplicate triplets can be skipped cleanly.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
solution.cpp