AmazonOA #354
Unique Pairs With Target Sum
Estimated EasyJudge-ready
Topics (AI-labelled)HashingTwo Pointers
Choose two different indices whose values sum to target. Order each pair internally by ascending value, output only distinct value pairs, and sort them in ascending numeric order of the first value and then the second value. Pairing a value with itself requires at least two occurrences, and duplicates in the input do not produce duplicate output.
Input
The first line contains n target and the second line contains n integers. On this site 0≤n≤200000, and the elements and target are all in −10^9..10^9.
Output
Output each distinct value pair as a,b on its own line (no parentheses, no spaces), in ascending numeric lexicographic order; if there is no answer, output a single line None.
Example 1
Input:
8 5
1 4 2 3 3 2 0 5
Output:
0,5
1,4
2,3
Example 2
Input:
4 10
1 2 3 4
Output:
None
Example 3
Input:
3 4
2 2 2
Output:
2,2
Example notes
The outputs of the three public examples are 0,5 / 1,4 / 2,3; None; and 2,2, checked by independent enumeration or direct simulation.
Editorial
Loading solution…