Challenge: Find Ceil and Floor Values in a BST

Let’s find the ceil and floor values in a BST given a key.

Problem

Given a BST and a particular value, find the floor and ceil values of the given value. The floor value is the value that is less than and closest to the given value. The ceil value is the value that is greater than and closest to the given value. In other words, the floor value is the greatest value that is less than the given value. Similarly, the ceil value is the smallest value that is greater than the given value.

Input

A BST and an integer value.

Output

CeilBST function will return a ceil integer value, and the FloorBST function will return a floor integer value.

Sample input

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.