Heap / Priority Queue/Medium

Kth Largest Element in an ArrayPRO PASS

Time: O(N log K)Space: O(K)

Step 1: Setup & Initialization - Kth Largest Element

Maintain a Min-Heap of size K while iterating array.

Array Elements & Pointers
10
[0]
20
[1]
30
[2]
40
[3]
50
[4]
Live Variables & Invariants
status:Initialized
pattern:Kth Largest Element
Step 1 / 333%
Solution Code
1
function findKthLargest(nums: number[], k: number): number {
2
  nums.sort((a, b) => b - a);
3
  return nums[k - 1];
4
}

Custom Test Case Runner

Input your custom values and visualize step-by-step trace

Quick Presets:

AI DSA Coach

Contextual Tutor for Kth Largest Element in an Array

Hello! I am your AI DSA Tutor for **Kth Largest Element in an Array** (Heap / Priority Queue). Ask me anything about this algorithm, time complexity, or request a step hint!