values. Find every distinct triple of numbers that can be picked from three different positions of the array so that the three numbers add up to zero.
Return each triple as a list of three numbers. Two triples made of the same numbers count as the same triple, even if they come from different positions, so each must appear in the answer only once. If no such triple exists, return an empty list.
Neither the order of the triples nor the order of numbers inside a triple matters.values=[3, -6, 2, 1, 3, -4, 0] → [[-6, 3, 3], [-4, 1, 3]]
Two triples work: −6 + 3 + 3 = 0 (the array has two 3s at different positions) and −4 + 1 + 3 = 0. The triple −4 + 2 + 2 does not count, since there is only one 2.
values=[5, 1, 2, 7] → []
All numbers are positive, so no triple sums to zero.
values=[0, 0, 0, 0, 0] → [[0, 0, 0]]
There are many zeros, but the all-zero triple appears in the answer only once.
values ≤ 3000values=[3, -6, 2, 1, 3, -4, 0]
[[-6, 3, 3], [-4, 1, 3]]
Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.