The problem. Given an integer array nums, return all the unique triplets [a, b, c] taken from three different positions such that a + b + c = 0. The answer must not contain the same triplet twice, and the order of the triplets doesn't matter.
Input: nums = [-1, 0, 1, 2, -1, -4]
Output: [[-1, -1, 2], [-1, 0, 1]]
Input: nums = [0, 1, 1]
Output: []
Input: nums = [0, 0, 0]
Output: [[0, 0, 0]]There are two separate challenges here: finding triplets that sum to 0 fast, and making sure each triplet appears once, even when the array has repeated values.
Free account
Sign up to read the rest of this lesson: 5 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come