Challenge: Find kth maximum value in Binary Search Tree

Given the root to a Binary Search Tree and a number "k" write a function to find the kth maximum value in the tree. A solution is placed in the "solution" section for your help, but we would suggest you to solve it on your own first.

Problem Statement

Implement a function find_kth_max(root,k) which will take a BST and any number “k” as an input and return kth maximum number from that tree.

Output

Returns kth maximum value from the given tree

Sample Input

bst = {
		6 -> 4,9
    4 -> 2,5
    9 -> 8,12
    12 -> 10,14
}
where parent -> leftChild,rightChild

k = 3

Sample Output

10

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