58. Pair With a Given Sum
Challenge1000 ms256 MBSolved by 0%
You are given an array and a target value k.
Print Yes if some two different positions in the array hold values that add up to
k, or No if no such pair exists.
The same position cannot be used twice, but two positions holding the same value are fine.
Constraints - `1 ≤ n ≤ 200000` - `-1000000 ≤ a[i] ≤ 1000000` - `-2000000 ≤ k ≤ 2000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
The third line contains an integer k.
Output
Print exactly one word: Yes or No.
Input5
2 7 11 15 3
9
OutputYes
Notehas the pair 2 and 7
Input4
1 2 3 4
100
OutputNo
Notehas no pair reaching the target
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.