Kth largest element
Medium Acceptance 64.92% Points 30.00
Given an array arr[] and a number k. The task is to find the kth largest element in the array.
Examples
Example 1

Input: arr[] = [10, 20, 4, 45, 99], k = 2
Output: 45
Explanation: The elements in the array sorted in descending order are: [99, 45, 20, 10, 4]. The 2nd largest element is 45.
Example 2

Input: arr[] = [1, 7, 8, 3, 9, 2], k = 4
Output: 3
Explanation: The elements in the array sorted in descending order are: [9, 8, 7, 3, 2, 1]. The 4th largest element is 3.
Hints
Hint 1
Expected Time Complexity: O(n log k)
Hint 2
Expected Auxiliary Space: O(k)
Constraints
- 1 <= k <= arr.size<= 10^6
- -106 <= k <= arr.size<= 10^6
Companies
Visa Google Oracle
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.