Kth Largest Element Problem Statement
Ninja enjoys working with numbers, and Alice challenges him to find the Kth largest value from a given list of numbers.
Input:
The first line contains an integer 'T', representing the number of test cases. For each test case: The first line contains two space-separated integers, 'N' and 'K', indicating the number of elements in the array and the Kth largest number to find, respectively.
Output:
For each test case, output an integer representing the Kth largest number on a new line.
Example:
Input:
2
5 2
4 5 1 3 2
6 4
7 10 4 3 20 15
Output:
4
10
Explanation:
In the first test case, the sorted array is [1, 2, 3, 4, 5]. The 2nd largest element is 4.
In the second test case, the sorted array is [3, 4, 7, 10, 15, 20]. The 4th largest element is 10.
Constraints:
1 <= T <= 50
1 <= K <= N <= 10^4
1 <= array[i] <= 10^5
Time Limit: 1 sec
Be the first one to answer
Add answer anonymously...
Top Paxcom India Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app