Loading...
Loading...
Loading...
A shop lists item prices from lowest to highest. A customer has an exact budget and wants to buy two different items that cost exactly that much. Print YES if such a pair exists and NO if it does not.
Example 1
Input
3 8 12 19 25 40 31
Output
YES
12 + 19 = 31.
Example 2
Input
2 5 9
Output
NO
Try the problem first. Open one hint at a time.
The prices are sorted, so put one pointer at each end.
If the sum is too small move the left pointer right. If it is too big move the right pointer left.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor