Kth Largest Element Problem Statement
Given an array of distinct positive integers and a number 'K', your task is to find the K'th largest element in the array.
Example:
Input:
Array: [2,1,5,6,3,8], K = 3
Output:
5
Explanation:
The sorted array is [8, 6, 5, 3, 2, 1], and the 3rd largest element is 5.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= ARR[i] <= 10^9
1 <= K <= N
- All elements are distinct.
Note:
The Kth largest element is the Kth element of the array when sorted in non-increasing order. You do not need to print anything; just implement the function.
Input:
The first line contains an integer 'T', the number of test cases. Each test case consists of two lines. The first line has two integers, 'N' and 'K'. The second line has 'N' space-separated integers, the array elements.
Output:
For each test case, output the Kth largest element in the array.
Be the first one to answer
Add answer anonymously...
Top Uber Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Uber 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