3Sum Problem
3Sum Problem — ExecCode Medium DSA Practice
Solve the 3Sum problem on ExecCode. Free online medium DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Find all unique triplets that sum to 0. Sort the array, fix one value i, then use left and right pointers to find the matching pair while skipping duplicates.
Examples
Input nums = [-1,0,1,2,-1,-4]; Output [[-1,-1,2],[-1,0,1]]. Input nums = [-2,0,0,2,2]; Output [[-2,0,2]]
Constraints
3 ≤ nums.length ≤ 3000 -10⁵ ≤ nums[i] ≤ 10⁵
Practice 3Sum free on ExecCode. Browse DSA problems, topic map, and placement guides.