DIY: Three Sum
Solve the interview question "Three Sum" in this lesson.
We'll cover the following
Problem statement
For this challenge, you are given a list called numbers
, containing positive and negative integers. Your job is to find unique triplets in the list that add up to zero: .
Input
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]
Output
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.