![]() |
VOOZH | about |
Given a Binary Search Tree and a number N, the task is to find the smallest number in the binary search tree that is greater than or equal to N. Print the value of the element if it exists otherwise print -1.
Examples:
Input: N = 20
Output: 21
Explanation: 21 is the smallest element greater than 20.Input: N = 18
Output: 19
Explanation: 19 is the smallest element greater than 18.
Approach:
The idea is to follow the recursive approach for solving the problem i.e. start searching for the element from the root.
Implementation:
19