Loading...
Loading...
Loading...
A binary search tree holds item prices. Given a target, print YES if two different nodes have prices that add up to it, and NO otherwise.
Example 1
Input
8 3 10 1 6 # 14 # # 4 7 13 17
Output
YES
Example 2
Input
8 3 10 1 6 # 14 # # 4 7 13 100
Output
NO
Try the problem first. Open one hint at a time.
Inorder gives a sorted list.
Then use one pointer at each end of the sorted list.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor