Kth Largest Element in an Array
MediumHeap
Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in sorted order, not the kth distinct element.
Example:
Input: nums = [3,2,1,5,6,4], k = 2
Output: 5
Explanation: The 2nd largest element is 5
Constraints:
- •
1 <= k <= nums.length <= 10^5 - •
-10^4 <= nums[i] <= 10^4
Kth Largest Element in an Array
MediumHeap
Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in sorted order, not the kth distinct element.
Example:
Input: nums = [3,2,1,5,6,4], k = 2
Output: 5
Explanation: The 2nd largest element is 5
Constraints:
- •
1 <= k <= nums.length <= 10^5 - •
-10^4 <= nums[i] <= 10^4
Press Run or Ctrl+Enter to execute