Step 1: Sort the array to make it easier to find quadruplets
[-2, -1, 0, 0, 1, 2]
Why: Sorting helps to avoid duplicates and use two-pointer technique efficiently
Step 2: Fix first number at index 0 (-2), then fix second number at index 1 (-1)
[-2, -1, 0, 0, 1, 2] ↑i=0 ↑j=1
Why: We pick first two numbers and look for remaining two numbers that sum to target minus these
Step 3: Use two pointers left=2 (0) and right=5 (2) to find pairs that sum to 3 (0 - (-2 + -1))
[-2, -1, 0, 0, 1, 2] i=0 j=1 left=2 right=5
Why: Two pointers help find pairs efficiently without checking all pairs
Step 4: Sum is -2 + -1 + 0 + 2 = -1, less than target 0, move left pointer right
[-2, -1, 0, 0, 1, 2] i=0 j=1 left=3 right=5
Why: Sum too small, increase sum by moving left pointer right
Step 5: Sum is -2 + -1 + 0 + 2 = -1 again, move left pointer right
[-2, -1, 0, 0, 1, 2] i=0 j=1 left=4 right=5
Why: Still less than target, move left pointer to increase sum
Step 6: Sum is -2 + -1 + 1 + 2 = 0, quadruplet found [-2, -1, 1, 2]
[-2, -1, 0, 0, 1, 2]
Why: Sum matches target, record quadruplet and move pointers to find more
Step 7: Move left pointer to 5 and right pointer to 4, pointers cross, move second number to index 2
[-2, -1, 0, 0, 1, 2] i=0 j=2
Why: No more pairs for this second number, move to next second number
Step 8: Repeat two pointer search for i=0, j=2 (0), left=3 (0), right=5 (2)
[-2, -1, 0, 0, 1, 2] i=0 j=2 left=3 right=5
Why: Find pairs that sum to 0 - (-2 + 0) = 2
Step 9: Sum is -2 + 0 + 0 + 2 = 0, quadruplet found [-2, 0, 0, 2]
[-2, -1, 0, 0, 1, 2]
Why: Sum matches target, record quadruplet
Step 10: Move left and right pointers, no more pairs, move first number to index 1
[-2, -1, 0, 0, 1, 2] i=1
Why: Finished all pairs for i=0, move to next first number
Step 11: Fix i=1 (-1), j=2 (0), left=3 (0), right=5 (2), target sum for pairs is 0 - (-1 + 0) = 1
[-2, -1, 0, 0, 1, 2] i=1 j=2 left=3 right=5
Why: Find pairs that sum to 1
Step 12: Sum is -1 + 0 + 0 + 2 = 1, quadruplet found [-1, 0, 0, 2]
[-2, -1, 0, 0, 1, 2]
Why: Sum matches target, record quadruplet
Step 13: Move pointers, sum no longer matches, finish search
[-2, -1, 0, 0, 1, 2]
Why: No more quadruplets found
Result: [-2, -1, 1, 2]
[-2, 0, 0, 2]
[-1, 0, 0, 1]