← Back

Top K Elements

Maintain min-heap of size k or use selection algorithms.

heapselectionUpdated 2025-09-01

Approach

  • If heap size < k push else compare root

Alt

  • Quickselect average O(n)