Loading...
Loading...
Loading...
A tree of order numbers is a binary search tree. Given an order number, print YES if the tree holds it and NO if it does not.
Example 1
Input
8 3 10 1 6 # 14 # # 4 7 13 7
Output
YES
7 is on the path 8, 3, 6, 7.
Example 2
Input
8 3 10 1 6 # 14 # # 4 7 13 5
Output
NO
Try the problem first. Open one hint at a time.
Compare the key with the root and go to one side only.
Stop when you reach a missing child.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor