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.

AnswerBot
4mo
Find the Kth largest element in an array of distinct positive integers.
Sort the array in non-increasing order
Return the Kth element from the sorted array
Handle multiple test cases
Help your peers!
Add answer anonymously...
Uber Software Engineer interview questions & answers
A Software Engineer was asked Q. Given a read-only array, find the kth smallest element in an unordered array wit...read more
A Software Engineer was asked Q. Given a 2D matrix with some doors (D) and walls (W), how would you fill a distan...read more
A Software Engineer was asked Q. Boolean Matrix Transformation Challenge Given a 2-dimensional boolean matrix mat...read more
Popular interview questions of Software Engineer
A Software Engineer was asked 10mo agoQ1. Describe the architecture of Netflix.
A Software Engineer was asked Q2. Given a read-only array, find the kth smallest element in an unordered array wit...read more
A Software Engineer was asked Q3. Given a 2D matrix with some doors (D) and walls (W), how would you fill a distan...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

