9. K-th Largest element in an array

Given an array nums, return the kth largest element in the array.

Example 1:

Input: nums = [1, 2, 3, 4, 5], k = 2

Output: 4

Example 2:

Input: nums = [-5, 4, 1, 2, -3], k = 5

Output: -5

Now Your Turn!

Pick the correct output for the given input

Input: nums = [11, 9, 8, 7, 3, 1], k = 4

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= nums.length <= 105
  • -1000 <= nums[i] <= 1000
  • 1 <= k <= nums.length

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int kthLargestElement(vector<int>& nums, int k) {
 
}
};
Test Case

Input:

K
Nums