Sum of Three
Medium
Question
Write a function where given an list of integers, returns all unique triplets of integers that sum up to 0.
The order of the output and the order of the triplets should be sorted.
Input: nums = [-1, 0, -2, 1, 3, 2]
Output: [[-2, -1, 3], [-2, 0, 2], [-1, 0, 1]]
Input: nums = [-2, -1, 0, 0, 2, -1, 2, -2]
Output: [[-2, 0, 2], [-1, -1, 2]]
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
If the given list is [-5, 2, 1, -4, 3], which of these would be a single valid triplet?
[-5, -4, 1]
[3, -4, 1]
[-4, 2, 2]
[]
All test cases pass! 🎉
Time limit exceeded
InputExpected OutputActual Output
Standard OutputScroll down...
Login or signup to save your code.
Uh oh... looks like you don't yet have access.
Not sure what this unlocks? Check out a free pattern section.