Heap pattern
Kth Largest Element in an Array
Given an integer array and a value k, return the kth largest element by rank in sorted order, which need not be a distinct value. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 215
- Medium
- 2 approaches
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
HeapLeetCode 215
Medium
From the first idea to the best one
- 01 Brute force · sort O(n log n)O(1) space
- 02 Optimized · size-k min-heap O(n log k)O(k) space
What you will learn
- How to read Kth Largest Element in an Array and spot the heap pattern in it
- Brute force · sort: O(n log n) time, O(1) space
- Optimized · size-k min-heap: O(n log k) time, O(k) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Heap
See Kth Largest Element in an Array run, step by step
Sign in and this page opens on the animation, with all 7 Heap problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.