886. Kth Largest Element in BST

EasyTreesBSTInorder

Given the root of a binary search tree and an integer k (1-indexed), return the k-th largest key in the BST. The input gives a level-order BST array and k separated by ' | '.

Input: A level-order BST array and k, separated by ' | '.

Output: Integer — the k-th largest key.

Examples

Example 1
Input: [8,3,10,1,6,null,14] | 2
Output: 10
Explanation: Largest keys 14,10; 2nd is 10.
Example 2
Input: [4,2,7,1,3] | 1
Output: 7
Explanation: Largest key.
Example 3
Input: [5] | 1
Output: 5
Explanation: Single node.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →