Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

Summit K

Learn
Play
Prove
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: Summit K.

A stale priority frontier increases wait time for everyone.

How you win

  1. 1Recognize when Top K heap matches the clues
  2. 2Keep this true after every move: the heap contains the k largest values seen so far
  3. 3Reach the result within O(n log k)

Rules and pressure

  • Target cost: O(n log k)
  • State rule: the heap contains the k largest values seen so far
Lesson 1 of 3

Live algorithm trace

Top K heap

Complete execution
1 of 8
3
scan
2
1
5
6
4

Begin with an empty min-heap that may hold two candidates.

1heap = []
2push each value
3if len(heap) > k: pop minimum
4return heap[0]
k = 2heap = []
Truth to preserve / Cost target
Truth to preserve

the heap contains the k largest values seen so far

Cost target

O(n log k)

A min-heap of size k remembers the k largest values seen. Its root is the weakest current candidate and is replaced when a stronger value arrives.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead