1/4
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress

Merge K Sorted Lists (H)
Min heap:
Push head of each non-empty list into heap
Pop smallest node, attach to result
Push popped node’s next into heap
Repeat until heap empty
Always extract current minimum
O(N log k)

K Closest Points to Origin
Use heap on distance:
Compute distance x^2 + y^2
Keep min heap of all points, or size-k max heap
Extract k closest
For size-k heap:
Push point
If heap size > k, pop farthest
O(n log k)

Top K Frequent Elements
Count + heap:
Build frequency map
Push (freq, num) into heap
Keep size k min heap
Remaining elements are top k frequent
Alternative: bucket sort

Find Median from Data Stream
Two heaps:
Max heap for smaller half
Min heap for larger half
Balance sizes so difference ≤ 1
Median:
odd: top of larger heap
even: average of both tops
Keeps halves ordered

Kth Largest Element in a Stream
Min heap of size k:
Push each new number
If heap size > k, pop smallest
Heap top is kth largest
Keeps only top k largest seen so far