DIY: Three Sum

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

We'll cover the following

Problem statement

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

Input

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

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

Output

The output will be an array of arrays representing the triplets that sum up to zero. The following is the output of the above input array:


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

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