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 pointer at index 0 (-2), second pointer at index 1 (-1)
[-2, -1, 0, 0, 1, 2]
first=0(-2), second=1(-1)
Why: Start searching pairs for the remaining two numbers
Step 3: Use two pointers: left=2(0), right=5(2), sum = -2 + -1 + 0 + 2 = -1 < 0, move left forward
[-2, -1, 0, 0, 1, 2]
first=0(-2), second=1(-1), left=3(0), right=5(2)
Why: Sum less than target, move left pointer to increase sum
Step 4: Sum = -2 + -1 + 0 + 2 = -1 < 0, move left forward to 4(1)
[-2, -1, 0, 0, 1, 2]
first=0(-2), second=1(-1), left=4(1), right=5(2)
Why: Still less than target, move left pointer
Step 5: Sum = -2 + -1 + 1 + 2 = 0, quadruplet found [-2, -1, 1, 2], move left and right to avoid duplicates
[-2, -1, 0, 0, 1, 2]
quadruplets: [[-2, -1, 1, 2]]
Why: Found a valid quadruplet, now skip duplicates
Step 6: Move second pointer to 2(0), left=3(0), right=5(2)
[-2, -1, 0, 0, 1, 2]
first=0(-2), second=2(0), left=3(0), right=5(2)
Why: Try new second pointer to find other quadruplets
Step 7: Sum = -2 + 0 + 0 + 2 = 0, quadruplet found [-2, 0, 0, 2], move left and right to avoid duplicates
quadruplets: [[-2, -1, 1, 2], [-2, 0, 0, 2]]
Why: Found another valid quadruplet
Step 8: Move first pointer to 1(-1), second pointer to 2(0), left=3(0), right=5(2)
first=1(-1), second=2(0), left=3(0), right=5(2)
Why: Try new first pointer to find more quadruplets
Step 9: Sum = -1 + 0 + 0 + 2 = 1 > 0, move right pointer left to 4(1)
first=1(-1), second=2(0), left=3(0), right=4(1)
Why: Sum too big, decrease by moving right pointer
Step 10: 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: Found last valid quadruplet
Result: [-2, -1, 1, 2] -> [-2, 0, 0, 2] -> [-1, 0, 0, 1]