Back to problems

Solve and optimize 3Sum and variants at scale

Algorithm · Snowflake · Hard

Given an integer array A with n elements and an integer T, implement a function that reports every distinct triplet of values drawn from three pairwise-different positions of A whose sum equals T. Inside a triplet the three values must be listed in nondecreasing order. The collection of triplets must itself be returned in lexicographic order, and it must not contain any repeated triplet: if the same three values can be picked from more than one choice of positions, that…

Checking your access…