Kth Largest Element Problem
Given an array containing N
distinct positive integers and a number K
, determine the Kth largest element in the array.
Example:
Input:
N = 6, K = 3, array = [2, 1, 5, 6, 3, 8]
Output:
5
Explanation:
Sorting the array in non-increasing order gives [8, 6, 5, 3, 2, 1]. The 3rd largest element is 5.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= ARR[i] <= 10^9
1 <= K <= N
Note:
Kth largest element in an array is the kth element when sorted in descending order. All elements are distinct.
Input:
The first line contains an integer 'T' representing the number of test cases. Each test case consists of two lines. The first line contains integers 'N' and 'K'. The second line contains 'N' space-separated integers of the array.
Output:
Print the Kth largest element for each test case.

AnswerBot
4mo
Find the Kth largest element in an array of distinct positive integers.
Sort the array in non-increasing order and return the Kth element.
Handle multiple test cases efficiently.
Ensure all elements in t...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Hexaware Technologies
Q. Can you write an essay on any topic and present it verbally?
Q. Shape and Method Overriding Problem Statement Create a base class called Shape t...read more
Q. Fishmonger Toll Optimization Problem A fishmonger needs to transport goods from ...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Hexaware Technologies Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
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

