CT024

BST Floor and Ceiling

MediumAcceptance: 0.0%

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:

Input: 7 5 3 7 1 4 6 8 2
Output: 1 3

Example 2:

Input: 3 5 3 7 5
Output: 5 5

Constraints:

1 <= n <= 10^4 -10^9 <= x, node value <= 10^9

Tags:

binary-search-tree trees binary-search
Loading...
Test Cases:No test cases
No test cases available.
Coding Problem Not Found | CodeTikki