#1985
Medium Algorithms Find the kth largest integer in the array
Array String Divide and Conquer Sorting Heap (Priority Queue) Quickselect
47.6% acceptance
Feb 25, 2026
1364
160
You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros.
Return the string that represents the kth largest integer in nums.
Note: Duplicate numbers should be counted distinctly. For example, if nums is ["1","2","2"], "2" is the first largest integer, "2" is the second-largest integer, and "1" is the third-largest integer.
Solution
Rust
Time O(n log n)
Space O(1)
impl Solution {
pub fn kth_largest_number(nums: Vec<String>, k: i32) -> String {
let mut nums = nums;
nums.sort_by(|a, b| {
if a.len() != b.len() {
a.len().cmp(&b.len())
} else {
a.cmp(b)
}
});
nums[nums.len() - k as usize].clone()
}
}