3Sum

Medium
ArrayTwo PointersSortingMetaAmazon
Given an integer array, print all unique triplets whose values sum to 0. Input format: - First line: n - Second line: n integers Sort each triplet in nondecreasing order. Print unique triplets in lexicographic order, one triplet per line. Print `EMPTY` if no triplet exists.

Constraints

3 <= n <= 3000
-10^5 <= nums[i] <= 10^5

Sample tests

Sample 1

Sample 2

Sign in to submit