Ceil Value from BST Problem Statement
Given a Binary Search Tree (BST) and an integer, write a function to return the ceil value of a particular key in the BST.
The ceil of an integer is defined as the smallest integer greater than or equal to the given number.
Explanation:
For example, if the array is arr[] = {1, 2, 5, 7, 8, 9}
and the key is 3
, the closest integer greater than 3 is 5. Hence, the ceil value is 5.
Input:
The first line contains an integer T, representing the number of test cases.
Each test case includes:
- A line with integers representing the BST nodes in level order, where '-1' indicates a null node.
- A line with an integer X, denoting the key value.
Output:
For each test case, output a single line with the ceil of integer X from the given BST.
Example:
Input:
For the following tree:
X values: 2, 7, 12
Output:
3
8
13
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 105
0 ≤ node data ≤ 109
1 ≤ X ≤ 109
- Time limit: 1 second
Note:
You do not need to print the output, just implement the function to compute the result.
Be the first one to answer
Add answer anonymously...
Top Paytm Full Stack Developer interview questions & answers
Popular interview questions of Full Stack Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app