← Search

Micro-Drill #71 — K largest elements

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.

Practice Problems

Related Coding Drills

← Micro #70 Micro #72 →