Problem context and objectives
Mission briefing
Matchmaking coordinator · Urgent players and jobs compete for limited slots
Keep the best next candidate available without sorting everything again: The Closest Stars.
A stale priority frontier increases wait time for everyone.
How you win
- 1Recognize when Bounded max-heap selection matches the clues
- 2Keep this true after every move: the heap contains the k closest processed points
- 3Reach the result within O(n log k)
Rules and pressure
- Target cost: O(n log k)
- State rule: the heap contains the k closest processed points
Lesson 1 of 3
Live algorithm trace
Bounded max-heap selection
Complete execution1 of 6
1,3
point
-2,2
5,8
0,1
Create a max-heap ordered by squared distance.
1
heap = max heap by squared distance2
push each point3
if heap size exceeds k: pop farthest4
sort the survivors deterministically5
return survivorsk = 2heap = []
Truth to preserve / Cost target
Truth to preserve
the heap contains the k closest processed points
Cost target
O(n log k)
Maintain a max-heap of k chosen points by squared distance. The root is the farthest current winner, so any closer point replaces it without storing or sorting every point.
Your call · What should guide every step of this algorithm?