Showing:
Handle Score
@Ibrahim Nash 5761
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
Closest Neighbor in BST
Easy Accuracy: 39.94% Submissions: 9071 Points: 2

Given a binary search tree and a number N, find the greatest number in the binary search tree that is less than or equal to N.

Example 1 :

Input : N = 24
Output : 21
Explanation : The greatest element in the tree which
is less than or equal to 24, is 21.
(Searching will be like 5->12->21)

Example 2 :

Input : N = 4
Output : 3
Explanation : The greatest element in the tree which
is less than or equal to 4, is 3.
(Searching will be like 5->2->3)

You don't need to read input or print anything. Your task is to complete the function findMaxForN() which takes the root of the BST, and the integer N as input paramters and returns the greatest element less than or equal to N in the given BST.

Expected Time Complexity: O(Height of the BST)
Expected Auxiliary Space: O(Height of the BST).

Constraints:
1<=N<=103