#9 most askedVery commonMediumTwo pointers
3Sum
New to Two pointers? Learn it from scratch firstTwo Pointers & Stacks โ
๐ข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.Return all unique triplets [a, b, c] in nums with a + b + c == 0. Each triplet should be sorted, and the list of triplets sorted too.
[-1, 0, 1, 2, -1, -4] โ [[-1, -1, 2], [-1, 0, 1]]
๐งช Practice
Write your solution, then press Run tests. Explain your approach out loud as you go.
def three_sum(nums):
pass
Output appears here. Press Run or Ctrl/โ + Enter.
Try it first. Struggling for a few minutes is how it sticks.