Loading...
Loading...
Loading...
Given a binary search tree and a number x, print the floor and the ceiling of x. The floor is the largest key that is at most x. The ceiling is the smallest key that is at least x. Print none for a missing one.
Example 1
Input
8 3 10 1 6 # 14 # # 4 7 13 5
Output
4 6
Example 2
Input
8 3 10 1 6 # 14 # # 4 7 13 8
Output
8 8
Try the problem first. Open one hint at a time.
Walk down as in search and remember the last candidate.
For the floor, a key at most x is a candidate and you go right. For the ceiling, a key at least x is a candidate and you go left.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor