Kth largest element in BST
Submissions: 18123   Accuracy:

42.26%

  Difficulty: Easy   Marks: 2

Given a Binary search tree. Your task is to complete the function which will return the Kth largest element without doing any modification in Binary Search Tree.
 

Input:
The first line of input contains an integer T, denoting the no of test cases. Then T test cases follow. Each test case consists of three lines. The first line of each test case contains an integer N denoting the no of elements in BST. Then in the next line are N space separated values of the BST. The third line of each test case contains an integer k for k largest element.

 

Output:
Print the kth largest element in each line.
 
Constraints:
1<=T<=20
1<=N , K<=20

 

Example(To be used only for expected output):
Input:

1
7
50 30 20 40 70 60 80
3
Output:
60

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth
Author: saksham seth


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.