Step 1: Sort the array to [-2, -1, 0, 0, 1, 2]
[-2, -1, 0, 0, 1, 2]
Why: Sorting helps to avoid duplicates and use two pointers efficiently
Step 2: Fix first number at index 0 (-2), second number at index 1 (-1), then use two pointers left=2, right=5
[-2, -1, 0, 0, 1, 2]
Indices: 0 1 [2] [5]
Why: We try to find two numbers between left and right that sum with fixed numbers to target
Step 3: Calculate sum: -2 + -1 + 0 + 2 = -1, less than target, move left pointer right
[-2, -1, 0, 0, 1, 2]
Indices: 0 1 [3] [5]
Why: Sum too small, increase sum by moving left pointer right
Step 4: Calculate sum: -2 + -1 + 0 + 2 = -1 again, move left pointer right
[-2, -1, 0, 0, 1, 2]
Indices: 0 1 [4] [5]
Why: Sum still less than target, move left pointer right
Step 5: Calculate sum: -2 + -1 + 1 + 2 = 0, quadruplet found [-2, -1, 1, 2]
Quadruplets: [[-2, -1, 1, 2]]
Why: Sum matches target, add quadruplet and move both pointers to avoid duplicates
Step 6: Move second number to index 2 (0), left=3, right=5
[-2, -1, 0, 0, 1, 2]
Indices: 0 [2] [3] [5]
Why: Try new second number to find other quadruplets
Step 7: Calculate sum: -2 + 0 + 0 + 2 = 0, quadruplet found [-2, 0, 0, 2]
Quadruplets: [[-2, -1, 1, 2], [-2, 0, 0, 2]]
Why: Sum matches target, add quadruplet and move pointers
Step 8: Move first number to index 1 (-1), second number to index 2 (0), left=3, right=5
[-2, -1, 0, 0, 1, 2]
Indices: [1] [2] [3] [5]
Why: Try new first and second numbers to find more quadruplets
Step 9: Calculate sum: -1 + 0 + 0 + 2 = 1, greater than target, move right pointer left
Indices: [1] [2] [3] [4]
Why: Sum too big, decrease sum by moving right pointer left
Step 10: Calculate sum: -1 + 0 + 0 + 1 = 0, quadruplet found [-1, 0, 0, 1]
Quadruplets: [[-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]]
Why: Sum matches target, add quadruplet and move pointers
Result: Quadruplets: [-2, -1, 1, 2] -> [-2, 0, 0, 2] -> [-1, 0, 0, 1]