Given an array of integers, find all unique triplets that sum to zero. Each triplet's values are returned in ascending order, and the result must not contain duplicate triplets.
Example 1
Explanation: Sorting first groups duplicates together, so fixing each distinct starting value once and sweeping the rest with two pointers finds both triplets without repeats.
Example 2
Explanation: No three values in the array sum to zero.
Example 3
Explanation: Even though the array holds three copies of the same value, only one triplet is returned — it's duplicate triplets that are eliminated, not duplicate values within a valid triplet.
How would you adapt this approach to find all unique quadruples (4Sum) that sum to a target?
Code execution is coming soon.