Loading...
Loading...
Loading...
Given n order amounts and a target, find out whether two different orders (two different positions in the list) add up exactly to the target. Print YES or NO.
Example 1
Input
5 14 8 3 11 5 9
Output
YES
3 + 11 = 14.
Example 2
Input
1 8 4
Output
NO
One order cannot be paired with itself.
Try the problem first. Open one hint at a time.
Checking every pair is too slow for 200,000 orders.
For each amount, ask whether target - amount has appeared before. A set answers that.
Check before adding the current amount to the set.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor