Katkat

Find the k-th largest element in an array

LinkedInSoftware Engineer · Onsite

Last 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 integers
  • k: integer (1 <= k <= len(nums))

Output

  • The k-th largest integer.

Constraints

  • 1 <= len(nums) <= 2 * 10^5
  • -10^9 <= nums[i] <= 10^9