Approach Summary
Sort the array and fix two outer loops, then use two pointers for the inner pair. Skip duplicates at every level.
How to Recognize This Pattern
- "Find all quadruplets summing to target"
- Generalises 3Sum with one more loop
Complexity Analysis
Time Complexity
O(n³)
Space Complexity
O(1)
Tags
Array Sorting Two Pointers