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

AnswerBot
4mo
The task is to find the Kth largest element from a given list of numbers for each test case.
Read the number of test cases 'T'
For each test case, read the number of elements 'N' and the Kth largest num...read more
Help your peers!
Add answer anonymously...
Paxcom India Software Engineer interview questions & answers
A Software Engineer was asked Q. Determine the Left View of a Binary Tree You are given a binary tree of integers...read more
A Software Engineer was asked Q. Maximize Expression Value Given an arithmetic expression EXP containing integer ...read more
A Software Engineer was asked Q. Sum Tree Conversion Convert a given binary tree into its sum tree. In a sum tree...read more
Popular interview questions of Software Engineer
A Software Engineer was asked Q1. Determine the Left View of a Binary Tree You are given a binary tree of integers...read more
A Software Engineer was asked Q2. Maximize Expression Value Given an arithmetic expression EXP containing integer ...read more
A Software Engineer was asked Q3. Sum Tree Conversion Convert a given binary tree into its sum tree. In a sum tree...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

