Triplets that cancel out
Given a list of integers nums, return every distinct triplet of values [a, b, c], taken from three different positions, with a + b + c == 0. Two triplets are the same if they hold the same values, so each must appear only once. The order of the triplets, and of the values inside each one, does not matter.
Aim for O(n²) time instead of checking every triple in O(n³).
Besides the tests, one large input (400 numbers, many repeats) with a ~250 ms limit (scaled to your device's speed): brute force won't pass.
Examples
zero_triplets([-1,0,1,2,-1,-4])→[[-1,-1,2],[-1,0,1]]zero_triplets([0,1,1])→[]zero_triplets([0,0,0])→[[0,0,0]]