Skip to content
playdsa
Preferences

Make yourself comfortable.

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

Theme
Advanced settings

The Cooldown Forge

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: The Cooldown Forge.

A stale priority frontier increases wait time for everyone.

How you win

  1. 1Recognize when Max-heap cooldown scheduling matches the clues
  2. 2Keep this true after every move: the heap contains every currently eligible task and the queue contains exactly cooling tasks
  3. 3Reach the result within O(total intervals log distinct tasks)

Rules and pressure

  • Target cost: O(total intervals log distinct tasks)
  • State rule: the heap contains every currently eligible task and the queue contains exactly cooling tasks

New words in this mission

Open a term for a plain-language explanation.
durable queue+

A waiting line that keeps work until a consumer finishes it. It absorbs bursts and lets failed work be retried.

Lesson 1 of 3

Live algorithm trace

Max-heap cooldown scheduling

Complete execution
1 of 6
A
task
B
idle
A
B
idle
A
B

Build a max-heap from the two task frequencies; the displayed slots preview the schedule being constructed.

1count tasks and build max heap
2release cooled tasks at current time
3pop the most frequent eligible task
4run it and decrement count
5queue it until time + n + 1
6advance time even when idle
7return elapsed time
counts = A:3,B:3cooldown = 2time = 0
Truth to preserve / Cost target
Truth to preserve

the heap contains every currently eligible task and the queue contains exactly cooling tasks

Cost target

O(total intervals log distinct tasks)

A max-heap prioritizes the task with the most copies left. Completed tasks wait in a cooldown queue until eligible again; each time unit either runs one task or records an unavoidable idle slot.

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