Sort the array first. Then fix each element nums[i] and use two pointers to find pairs that sum to -nums[i].
Why sorting? It enables the two-pointer technique. If the current sum is too small, move the left pointer right. If too large, move the right pointer left.
To avoid duplicate triplets, skip elements that equal their predecessor. After finding a valid triplet, also skip duplicate left and right values before continuing.
With nums = [-4, -1, -1, 0, 1, 2] (sorted), fix -1 at index 1. Left starts at -1 (index 2), right at 2 (index 5). Sum = -1 + (-1) + 2 = 0. Found one triplet.