← Search
Search Target: 10s
nlargest uses a min-heap of size k internally. O(n log k) for top-k problems.
import heapq top_k = heapq.nlargest(k, a)
Type it from memory. Go.