Step 1: Sort the array to make it easier to find triplets
[-4, -1, -1, 0, 1, 2]
Why: Sorting helps us use two pointers to find pairs that sum to a target efficiently
Step 2: Fix first element at index 0 (-4), set left=1, right=5
[-4, -1, -1, 0, 1, 2]
first = -4, left = -1, right = 2
Why: We 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, less than 0, move left pointer right
[-4, -1, -1, 0, 1, 2]
first = -4, left = -1 (index 2), right = 2
Why: Sum too small, increase sum by moving left pointer right
Step 4: Sum = -4 + (-1) + 2 = -3 again, move left pointer right
[-4, -1, -1, 0, 1, 2]
first = -4, left = 0 (index 3), right = 2
Why: Still too small, move left pointer right
Step 5: Sum = -4 + 0 + 2 = -2, move left pointer right
[-4, -1, -1, 0, 1, 2]
first = -4, left = 1 (index 4), right = 2
Why: Sum still less than zero, move left pointer right
Step 6: Sum = -4 + 1 + 2 = -1, move left pointer right
[-4, -1, -1, 0, 1, 2]
first = -4, left = 2 (index 5), right = 2
Why: Left pointer meets right, no triplet with first = -4
Step 7: Fix first element at index 1 (-1), set left=2, right=5
[-4, -1, -1, 0, 1, 2]
first = -1, left = -1, right = 2
Why: Try to find pairs that sum to 1 (because -1 + x + y = 0 means x + y = 1)
Step 8: Sum = -1 + (-1) + 2 = 0, found triplet [-1, -1, 2], move left and right pointers
[-4, -1, -1, 0, 1, 2]
triplets = [[-1, -1, 2]]
left = 3 (0), right = 4 (1)
Why: Sum zero means valid triplet, move pointers to find other triplets
Step 9: Sum = -1 + 0 + 1 = 0, found triplet [-1, 0, 1], move left and right pointers
[-4, -1, -1, 0, 1, 2]
triplets = [[-1, -1, 2], [-1, 0, 1]]
left = 4, right = 3
Why: Sum zero again, add triplet and move pointers
Step 10: Left pointer crossed right, move first pointer to index 2 (-1) but skip duplicate
[-4, -1, -1, 0, 1, 2]
first = -1 (index 2) skipped
Why: Avoid duplicate triplets by skipping same first element
Step 11: Fix first element at index 3 (0), set left=4, right=5
[-4, -1, -1, 0, 1, 2]
first = 0, left = 4, right = 5
Why: Try to find pairs that sum to 0 (0 + x + y = 0 means x + y = 0)
Step 12: Sum = 0 + 1 + 2 = 3, sum too big, move right pointer left
[-4, -1, -1, 0, 1, 2]
first = 0, left = 4, right = 4
Why: Sum too large, decrease sum by moving right pointer left
Step 13: Left pointer crossed right, stop
[-4, -1, -1, 0, 1, 2]
Why: No more pairs to check with first = 0
Result: [-1, -1, 2] -> [-1, 0, 1] -> null