workshop private

← all creations

Frame

viz · created 2026-09-25

The LC 621 Task Scheduler greedy drawn as the grid the most frequent task fixes — f − 1 rows of width n + 1 plus a tail, every other letter dropped in column by column, the idle cells appearing behind the walk or the rows stretching past the frame — with the fill order and the final max(tasks, frame) each switchable to its bug.

algorithmsinterview-prepcanvas

Task Scheduler (LC 621) has a two-line closed form, and the line everybody memorises — max(len, (f − 1)(n + 1) + m) — hides the picture that makes it obvious. The most frequent letter, with f copies and n intervals of cooldown between each pair, has to occupy f cells spaced n + 1 apart before any other letter is placed. Draw those as f − 1 rows of width n + 1 and one more cell: that is the frame, and it is a lower bound on its own. Every other letter that also has count f adds a column to it (m columns in all). The only question left is whether the remaining letters settle into the frame’s empty cells or spill past its right edge — and once anything spills, every row stretches and there is no idle interval anywhere, so the answer is simply the number of tasks.

Three layers, top to bottom:

Two switches. Fill the rest → in arrival order keeps the frame and the column walk but drops the remaining letters in the order they first appear instead of by count. The bound is unchanged; the construction breaks: a letter with count exactly f − 1 that starts mid-column wraps into the next column, and its wrap pair reads one row minus one apart — n, one short of the cooldown. The wrap case (AAABCC, n = 2) is the two-second reproduction: the strip marks the pair red and says 2 apart — needs 3. The sort is what guarantees that count-(f − 1) letters come first among the rest and each gets a whole column. Final answer → frame only returns the bound without comparing it to the task count; overflow (AAABBBCCCDDDEE, n = 2) shows it returning 10 for 14 tasks, in red, with the stretched rows above saying why.

Presets: the three LC examples, the wrap case, overflow, and random. The tasks box takes any string of letters (up to 40); n goes to 12.

Reuse

src/frame.js is a framework-free ES module:

No rendering or timers in the module; the canvas demo is reference code.

Gotchas