Algorithms Playbook
← All problems
MediumTwo pointers →Similar to: 3Sum

Three that cancel out

Problem

Given an integer array nums, return all unique triplets [a, b, c] with a + b + c = 0. The answer must not contain duplicate triplets.

Examples

Input: [-1, 0, 1, 2, -1, -4]

Output: [[-1, -1, 2], [-1, 0, 1]]

Input: [0, 0, 0]

Output: [[0, 0, 0]]

Hints

    Try it first. Every hint reveals a bit more.

    Solution