Dsa
Binary Search Tree
Medium
Find Kth Largest Element in BST
Given a binary search tree (BST) and an integer k, return the kth largest element in the BST. The kth largest element is the element that would be in the kth position if the elements were sorted in descending order.
Input Format:
- The first line contains an integer n, the number of nodes in the BST.
- The next n lines each contain a single integer x, denoting the value of a node.
- The final line contains an integer k.
Output Format:
- Output the kth largest element in the BST.
Example:
Input:
5
3
1
4
6
5
2
Output:
4
Key concepts
binary_search_treerecursiontraversal
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now