Kth Largest Element in an Array
Try to solve the Kth Largest Element in an Array problem.
Statement
Given an integer array, nums
, and an integer, k
, determine and return the kth
largest element in the array.
Note: The
kth
largest element is defined with respect to the array’s sorted order (descending), and does not necessarily correspond to thekth
unique value.
Constraints:
-
k
nums.length
-
nums[i]
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Kth Largest Element in an Array
What is the 4th largest element in the following unsorted array?
[5, 12, 9, 0, 6, 7, 1, 8, 4, 9]
9
7
8
6
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in the following coding playground:
package mainfunc findKthLargest(nums []int, k int) int {// Replace this placeholder return statement with your codereturn -1}