Find the k-th largest element in an array
LinkedInSoftware Engineer · OnsiteLast updated
This question evaluates proficiency with selection algorithms, array manipulation, and analysis of time and space complexity, reflecting competency in order-statistics and basic data structures.
Given an integer array nums and an integer k, return the k-th largest element in the array.
Notes:
- The k-th largest element is the element that would appear in position
k(1-indexed) if the array were sorted in descending order. - Do not fully sort the array unless you want to (but consider performance).
Input
nums: array of integersk: integer (1 <= k <= len(nums))
Output
- The k-th largest integer.
Constraints
1 <= len(nums) <= 2 * 10^5-10^9 <= nums[i] <= 10^9
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.