Medium · Binary Search
Kth Largest Element in an Array
Given an integer array nums and an integer k, return the kth largest element: the element at position k when the array is sorted in descending order, with duplicates counted separately.
Examples
Example 1
[3,2,1,5,6,4], k=2 → 5Output: 5
Example 2
[3,2,3,1,2,4,5,5,6], k=4 → 4Output: 4
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.