FrontendInterviews.dev

Loading problem…

288. Kth Largest Element in an Array

Medium•
Acceptance: 100.00%
•
🔓3/3 Pro unlocks today

Given an integer array nums and integer k, return the kth largest element in the array.

Note: this is the kth element in sorted order, not the kth distinct element.

Requirements

Implement:

function findKthLargest(nums, k) {}

Example Usage

findKthLargest([3, 2, 1, 5, 6, 4], 2);
// 5

findKthLargest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4);
// 4

Constraints

  • 1 <= k <= nums.length
  • Use efficient selection approach where possible
  • Handle duplicates correctly