190. Distinct Pairs with Sum
MediumHash Set
Count distinct value pairs {x, y} (x ≤ y, from different positions) with x + y = k.
Input format
Line 1: n k Line 2: n integers
Output format
The number of distinct pairs.
Example 1
Input
6 6 1 5 3 3 5 1
Output
2
Example 2
Input
4 2 1 1 1 1
Output
1
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…