Step 1: Sort the array
[-4, -1, -1, 0, 1, 2]
Why: Sorting helps to avoid duplicates and use two-pointer technique
Step 2: Pick first element nums[0] = -4, set left=1, right=5
[-4, -1, -1, 0, 1, 2]
first=-4, left=-1, right=2
Why: Try to find two numbers that sum to 4 (because -4 + x + y = 0 means x + y = 4)
Step 3: Sum = -4 + (-1) + 2 = -3 < 0, move left pointer right
[-4, -1, -1, 0, 1, 2]
first=-4, left=-1, right=2
Why: Sum too small, increase left to get bigger sum
Step 4: Sum = -4 + (-1) + 2 = -3 < 0, move left pointer right
[-4, -1, -1, 0, 1, 2]
first=-4, left=0, right=2
Why: Still too small, move left pointer
Step 5: No triplet found with first = -4, move to next first element nums[1] = -1
[-4, -1, -1, 0, 1, 2]
first=-1, left=2, right=5
Why: Try new first element to find triplets
Step 6: Sum = -1 + (-1) + 2 = 0, found triplet [-1, -1, 2], move left and right to avoid duplicates
[-4, -1, -1, 0, 1, 2]
triplets: [[-1, -1, 2]]
Why: Found valid triplet, move pointers to find others
Step 7: Sum = -1 + 0 + 1 = 0, found triplet [-1, 0, 1], move left and right
[-4, -1, -1, 0, 1, 2]
triplets: [[-1, -1, 2], [-1, 0, 1]]
Why: Found another valid triplet
Step 8: Move to next first element nums[2] = -1 (skip duplicate), then nums[3] = 0
[-4, -1, -1, 0, 1, 2]
triplets: [[-1, -1, 2], [-1, 0, 1]]
Why: Avoid duplicate first elements to prevent repeated triplets
Step 9: With first=0, left=4, right=5, sum=0+1+2=3 > 0, move right pointer left
[-4, -1, -1, 0, 1, 2]
triplets: [[-1, -1, 2], [-1, 0, 1]]
Why: Sum too big, decrease right pointer
Step 10: left and right pointers cross, no more triplets with first=0
[-4, -1, -1, 0, 1, 2]
triplets: [[-1, -1, 2], [-1, 0, 1]]
Why: No more pairs to check
Result: [-1, -1, 2] -> [-1, 0, 1]
All unique triplets found