Return all unique triplets [a, b, c] from the list such that a + b + c = 0. Each triplet must be sorted ascending, and the outer list of triplets is returned in ascending order. There must be no duplicate triplets. Return an empty list for null input or fewer than 3 elements.
Examples:
Input: nums = [-1, 0, 1, 2, -1, -4]
Output: [[-1, -1, 2], [-1, 0, 1]]
Explanation: These are the only two unique triplets that sum to zero
Input: nums = [0, 0, 0]
Output: [[0, 0, 0]]
Explanation: Only one triplet is possible and it sums to zero
Input: nums = [1, 2, 3]
Output: []
Explanation: No triplet sums to zero
Input: nums = []
Output: []
Explanation: Empty list returns an empty list
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 All Time Leaderboard
Contest runs January 1, 1970 - December 31, 9999. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.