VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 09: Heaps and top-k

Lesson 9.6 of 12 in this module Unrolled Pro

Task Scheduler

The fewest time slots to run tasks when equal tasks must be at least n slots apart. From a step-by-step simulation that scans every task type at every slot, to a heap of remaining counts plus a cooldown queue that schedules the most remaining task that's ready (O(T log 26)), to a counting formula built around the most frequent task (O(T)). Then producing the actual order, rearranging a string so no two equal letters touch, and the ML version: round-robin GPU jobs across tenants with a per-tenant cooldown.

about 15 min 5 Python examples 2 quick checks

Problem. tasks is a list of task labels (letters A–Z). Each takes one time slot. Two runs of the same label must be separated by at least n slots (other tasks or idle slots in between). Return the minimum number of slots to run everything.

text
tasks = A A A B B B, n = 2   →   8      A B _ A B _ A B
tasks = A A A B B B, n = 0   →   6      no cooldown
tasks = A A A A A A B C D E F G, n = 2   →   16   A B C A D E A F G A _ _ A _ _ A

The greedy question at every slot: which ready task should run now? Answer: the one with the most copies left, because it's the one most likely to force idle slots later. A heap answers "the most remaining" in O(log) per step.

ML context. Schedulers in ML infrastructure face the same constraint: a tenant may submit at most one job per GPU every few minutes (rate limiting), a dataset shard shouldn't be read twice within a window, an evaluation suite can't rerun the same model within a cooldown. "Most remaining work first, among those allowed now" keeps throughput high and idle time low (Change C).


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Task Scheduler"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee