Unique zero-sum triples
Return all distinct nondecreasing value triples summing to zero, in lexicographic order, as lists. Do not mutate the input.
values = sorted([-1, 0, 1, 2])
print(values[0]+values[1]+values[-1])Reason about the state
Sort a copy, fix the first value and use two pointers for the remaining pair. Skip duplicate first values and duplicate pairs for quadratic time. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return all distinct nondecreasing value triples summing to zero, in lexicographic order, as lists. Do not mutate the input.
The explanation opens here once every check passes.