Given an integer array nums, return all unique triplets [nums[i], nums[j], nums[k]] such that i, j and k are distinct indices and the three values sum to zero. The result must not contain duplicate triplets.
nums = [-1,0,1,2,-1,-4][[-1,-1,2],[-1,0,1]]nums = [0,1,1][]Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →Two indices move through a sorted (or sortable) structure — often from opposite ends or at different speeds — to avoid the nested loops a brute-force scan would need.
Read the full Two Pointers guide →
Original problem on LeetCode ↗