Find Unique Zero-Sum Triplets
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Find unique zero-sum triplets with distinct indices, deterministic ordering, careful duplicate suppression, and explicit time and space analysis.
Read the full Microsoft Software Engineer interview experience this question came from
Constraints
- 0 <= len(nums) <= 3000.
- Every input value is an integer from -1,000,000 through 1,000,000 inclusive.
- Each triplet uses three distinct input indices; equal values require sufficient input multiplicity.
- Return each value triplet once, internally ascending; sort the outer result lexicographically.
- Reordering the input or sorting a copy is allowed; return values, not indices.
Examples
Input: ([-1, 0, 1, 2, -1, -4],)
Expected Output: [[-1, -1, 2], [-1, 0, 1]]
Explanation: The source example contains exactly these two distinct triplets, in lexicographic order.
Input: ([0, 0, 0, 0],)
Expected Output: [[0, 0, 0]]
Explanation: Four available indices permit a zero triplet; all choices have the same values.
Hints
- Check that each output triplet uses three distinct indices and that both required ordering rules are satisfied.