DIY: Three Sum

Solve the interview question "Three Sum" in this lesson.

Problem statement

For this challenge, you are given a list called numbers, containing positive and negative integers. Your job is to find unique triplets (a,b,c)(a, b, c) in the list that add up to zero: (a+b+c)=0(a + b + c) = 0.


The function’s input will be a list containing positive and negative integers. The following is an example input:

[3, 0, 6, 2, 5, -8, -1]


The output will be a list of lists representing the triplets that sum up to zero. The following is the output of the above input list:

[[-8, 5, 3], [-8, 6, 2]]

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.