Skip to main content
Back to problems
#215
Medium Algorithms

Kth largest element in an array

Array Divide and Conquer Sorting Heap (Priority Queue) Quickselect
68.8% acceptance
Jan 12, 2026
18678
968
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 the sorted order, not the kth distinct element. Can you solve it without sorting?

Solution

Rust
Time O(1)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn find_kth_largest(mut nums: Vec<i32>, k: i32) -> i32 {
    nums.sort_unstable_by(|a, b| b.cmp(a));
    nums[k as usize - 1]
  }
}