Find Median From a Data Stream With Two Heaps
The two-heap balance: max-heap low half, min-heap high half. Python solution and complexity analysis for the heap and top-k interview pattern.
Tag
Articles tagged Heap Top K on The Augmented Dev.
11 articles
The two-heap balance: max-heap low half, min-heap high half. Python solution and complexity analysis for the heap and top-k interview pattern.
Bounded max-heap on squared distance — monotone transforms are free. Python solution and complexity analysis for the heap and top-k interview pattern.
Explore an implicit sorted matrix — seed one row, expand neighbors lazily. Python solution and complexity analysis for the heap and top-k interview pattern.
The bounded min-heap of size k — and when quickselect beats it. Python solution and complexity analysis for the heap and top-k interview pattern.
Design a class where the size-k min-heap is the entire state. Python solution and complexity analysis for the heap and top-k interview pattern.
Repeatedly smash the two heaviest — negation makes heapq a max-heap. Python solution and complexity analysis for the heap and top-k interview pattern.
K-way merge in O(n log k) — with the tuple tie-break heapq requires. Python solution and complexity analysis for the heap and top-k interview pattern.
No two equal neighbors — alternate the two most frequent letters. Python solution and complexity analysis for the heap and top-k interview pattern.
Rebuild a string most-frequent-first — full ordering, so no bounded trick. Python solution and complexity analysis for the heap and top-k interview pattern.
CPU cooldown scheduling — the frame formula and when idle time vanishes. Python solution and complexity analysis for the heap and top-k interview pattern.
Counter plus bounded heap — and the bucket-sort answer that beats it. Python solution and complexity analysis for the heap and top-k interview pattern.