educative.io

Define unique: value or index in array?

Problem statement:

Given an array of unsorted numbers, find all unique triplets in it that add up to zero .

First example:

Input: [-3, 0, 1, 2, -1, 1, -2]
Output: [-3, 1, 2], [-2, 0, 2], **[-2, 1, 1]**, [-1, 0, 1]

Third triplet contains two ones. Therefore, by unique, do you mean unique indexes from the array, and not unique values?

Unique triplets mean that the triplets need to be unique comparing to each other. For example, [-2, 1, 1] and [1, 1, -2] have the same numbers, so only one of them should be included in the answer.

2 Likes

Thanks for clarifying! On second thought, it’s is fairly obvious.