Given an array arr[] and a number k. The task is to find the kth largest element in the array.

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.

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.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
10 20 4 45 99 2
45
1 7 8 3 9 2 4
3