Grokking the Engineering Manager Coding Interview
Ask Author
Back to course home

0% completed

Triplet Sum to Zero (medium)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given an array of unsorted numbers, find all unique triplets in it that add up to zero.

Examples

Example 1

  • Input: [-3, 0, 1, 2, -1, 1, -2]
  • Output: [[-3, 1, 2], [-2, 0, 2], [-2, 1, 1], [-1, 0, 1]]
  • Explanation: There are four unique triplets whose sum is equal to zero.

Example 2

  • Input: [-5, 2, -1, -2, 3]
  • Output: [[-5, 2, 3], [-2, -1, 3]]
  • Explanation: There are two unique triplets whose sum is equal to zero.

Constraints:

  • 3 <= arr.length <= 3000
  • -10<sup>5</sup> <= arr[i] <= 10<sup>5</sup>

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible