A video editor’s caption track
Subtitlers work on a caption track: the lesson’s growing array, holding a film’s caption cues in order. Its buffer, from the checker’s plumbing, counts every cue written into a slot (a copy, a shift or a new cue), so the checker can tell a correct operation that is too slow from one that scales, however the code is written. Each level starts from the previous level’s finished code, so you can begin at any of them.
Subtitlers paste whole scenes of captions copied from another cut, and import subtitle files with thousands of cues. A teammate added a paste method, and a reserve method for imports, which know the cue count up front. Pasting a long scene near the start of a feature film makes the editor stall.
Pasting k cues one at a time moves every cue after the paste point k times over, and an import without reserve copies the whole track at every doubling. Both scale badly with long films.
Reproduce A three-cue track: track.insertAll(1, ["(phone rings)", "Hello?"]) gives the right cues but spends 10 moves; growing once (3 copies), shifting two cues and writing two should need 7. track.reserve(1000) does nothing yet.
Acceptance criteria Pasting a block puts it at the index in order, moving the cues after it once, by the block’s length: at most n − i shifts and k writes, plus n copies if the track grows. reserve(capacity) makes room for at least that many cues without losing or reordering any; a smaller request changes nothing. After reserve(n), appending n cues to an empty track costs n moves: only the writes. insert still works as before. Notes Cases print the cues (for a long track, its length and the cues around the end of the paste), the capacity (or “room for n” when the track has room for at least n), and whether the operation stayed within its budget of moves. The buffer counts the moves, as before: every set on the track’s Slots is one. Keep the track’s fields and its methods’ names and signatures; the checker calls them.