The Codetikki librarians use a binary search tree to organize scrolls. For any target value, they want to find the closest scroll above (ceiling) and below (floor). Given a BST and a target value x, find the floor (largest value <= x) and ceiling (smallest value >= x). Input: first line n, second line n space-separated BST values in level-order (with "null" for absent), third line x. Output: floor and ceiling separated by space, or "null" if either does not exist.
Example 1:
Example 2:
Constraints:
1 <= n <= 10^4 -10^9 <= x, node value <= 10^9
Tags:
