DAYS
HOUR
MINS
SEC
Error
Given a Binary Search Tree of size N, find the Median of its Node values.
Example 1:
Input:
6
/ \
3 8
/ \ / \
1 4 7 9
Output: 6
Explanation: Inorder of Given BST will be:
1, 3, 4, 6, 7, 8, 9. So, here median will 6.
Example 2:
Input: 6 / \ 3 8 / \ / 1 4 7 Output: 5 Explanation:Inorder of Given BST will be: 1, 3, 4, 6, 7, 8. So, here median will (4 + 6)/2 = 10/2 = 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMedian() which takes the root of the Binary Search Tree as input and returns the Median of Node values in the given BST.
Median of the BST is:
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1<=N<=1000
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes