Skip to main content
mediumBlind 75

3Sum

Return all unique triplets that sum to zero. Each triplet sorted ascending; the list of triplets sorted ascending too. Example: [-1,0,1,2,-1,-4] => [[-1,-1,2],[-1,0,1]]

3Sum is Two Sum with a twist: sort first, then walk two pointers inward for each anchor. The real trick is skipping duplicates cleanly so your answer set stays unique. Nail that and you have a template for 4Sum and every k-sum that follows.

Arrays & HashingTwo Pointers

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Typing with Coco is free when you sign in, up to a daily limit. Talking with her out loud comes with the $79 pack. Anyone can open the editor and run their code.

13Summedium
Based onLeetCode