1. Sort the input array in non-decreasing order. Sorting is essential for eliminating duplicate triplets and optimizing the algorithm.
2. Initialize an empty list to store the unique triplets.
3. Iterate through the array using a fixed element as a potential candidate for the first number in the triplet.
4. Inside the outer loop, use two pointers (left and right) to find the remaining two elements that sum up to the negative of the fixed element.
5. Move the left pointer to the right if the sum is less than zero and move the right pointer to the left if the sum is greater than zero. Adjust the pointers until a triplet is found or they meet.
6. Check for duplicate triplets and skip them to avoid redundancy.
7. Add the triplet to the result list if it is unique.
8. Continue the outer loop until all possible fixed elements are considered.
9. Return the list of unique triplets.
Click for My Solution in Github