CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsTwo Pointers

3Sum

Medium
LeetCode
3/7
MediumTwo PointersLeetCode #15

3Sum

Sort. Fix one index; two-sum the rest with two pointers. Skip duplicates.

Examples

Example 1

Input

6
-1 0 1 2 -1 -4

Output

-1 -1 2 | -1 0 1
Example 2

Input

3
0 1 1

Output

Stuck? Take a nudge

C++17Autosaves