...

/

Kth Largest Element in an Array

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 the kth unique value.

Constraints:

  • 11 \leq k \leq nums.length 103\leq 10^3

  • 104-10^4 \leq nums[i] 104\leq 10^4

Examples

canvasAnimation-image
1 / 4

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

1.

What is the 4th largest element in the following unsorted array?

[5, 12, 9, 0, 6, 7, 1, 8, 4, 9]

A.

9

B.

7

C.

8

D.

6


1 / 4

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.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4

Try it yourself

Implement your solution in the following coding playground:

Go
usercode > main.go
package main
func findKthLargest(nums []int, k int) int {
// Replace this placeholder return statement with your code
return -1
}
Kth Largest Element in an Array

Access this course and 1200+ top-rated courses and projects.