The problem. Given an integer array nums and an integer k, return the kth largest element — the kth largest in sorted order, so duplicates count separately, not the kth distinct value. 1 ≤ k ≤ nums.length.
nums = [3, 2, 1, 5, 6, 4], k = 2 -> 5
nums = [3, 2, 3, 1, 2, 4, 5, 5, 6], k = 4 -> 4 (6, 5, 5, 4: duplicates count)
nums = [7], k = 1 -> 7Members only · free account
The rest of this lesson, with 6 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson