Here is the interview question prompt, presented for reference.
Given an integer array
nums, return all the triplets
[nums[i], nums[j], nums[k]] such that
i != j,
i != k, and
j != k, and
nums[i] + nums[j] + nums[k] == 0. The solution must not contain any duplicate triplets, and the order of numbers in the triplet must be in ascending order.
For example, consider the following array,
nums = [-2, 1, -3, 5, -3, 5]
If we look closely, there are a lot of duplicate elements here. The unique triplet that gives the sum as 0 is
[-3, -2, 5]. This triplet can be formed from numbers at indices 0, 2, and 3. It can also be formed from numbers at indices 0, 4, and 5. Since we are avoiding duplicates, we consider only one unique triplet to be the correct solution, regardless of the indices.
You can see the full challenge with visuals at this link.
Challenges • Asked about 1 year ago by Jake from AlgoDaily