#K46102. Three Sum Zero: Find Unique Triplets Summing to Zero

    ID: 27902 Type: Default 1000ms 256MiB

Three Sum Zero: Find Unique Triplets Summing to Zero

Three Sum Zero: Find Unique Triplets Summing to Zero

In this problem, you are given an array of integers. Your task is to find all unique triplets ((a, b, c)) in the array such that: [ a + b + c = 0 ] Each triplet should be sorted in non-decreasing order, and the complete list of triplets must be printed in lexicographical order.

Example: For an input array [-1, 0, 1, 2, -1, -4], the expected output is [[-1, -1, 2], [-1, 0, 1]].

inputFormat

The first line contains a single integer (n), representing the number of elements in the array. The second line contains (n) space-separated integers.

outputFormat

Output the list of unique triplets (each triplet is a list of three integers) whose sum is zero. The output must be in the Python list format. If no triplet exists, output an empty list [].## sample

6
-1 0 1 2 -1 -4
[[-1, -1, 2], [-1, 0, 1]]