179. Triplets with Zero Sum
MediumTwo PointersSorting
Print the number of distinct value triplets (a ≤ b ≤ c taken from different positions) with a + b + c = 0.
Input format
Line 1: n Line 2: n integers
Output format
The number of distinct triplets.
Example 1
Input
6 -1 0 1 2 -1 -4
Output
2
Example 2
Input
3 0 1 1
Output
0
Constraints
1 ≤ n ≤ 3000
Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.
Loading the MyLoginn IDE…