Skip to interview prep
Apexed

28. K Largest Elements

EasyPriority queues & heaps

Return the k largest elements of nums in descending order. Repeated values count separately.

Example 1

Input: nums = [3, 1, 5, 12, 2, 11], k = 3
Output: [12, 11, 5]

Constraints

  • 0 ≤ k ≤ nums.length ≤ 10⁵

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

K Largest Elements — coding interview practice — Apexed