Concept Flow - Four Sum Problem All Unique Quadruplets
Sort the array
Fix first number i
Fix second number j
Set left = j+1, right = end
While left < right
Sum == target?
Add quadruplet
Skip duplicates
Repeat until left >= right
Skip duplicates for j
Repeat for j
Skip duplicates for i
Repeat for i
Return all unique quadruplets
The array is sorted first. Then two nested loops fix the first two numbers. Two pointers move inward to find pairs that sum to the target minus the first two. Duplicates are skipped to ensure unique quadruplets.
