Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Sort the array first. Fix one element with an outer loop, then use two converging pointers on the remaining subarray to find pairs that sum to the negation of the fixed element. Skip duplicate values at each level to ensure unique triplets.
Sorting enables the two-pointer technique: if the current sum is too small, move the left pointer right to increase it; if too large, move right pointer left. Skipping duplicates prevents repeated triplets.
Updated Feb 2026