K-th largest element in BST

TopicDifficultyCompanies
Binary Search Tree
MEDIUM
Amazon

Given a binary search tree, write a program to find the kth largest element in it.

Problem Note

  • You may assume k is always valid, 1 ≤ k ≤ BST's total elements.

Example

Input:  k = 3 and fllowing is the tree
10
/ \
4 20
/ / \
2 15 40
Output: 15
Explanation: 15 is the 3rd largest element in the BST.

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.