Archive backlog replay
An archive writer keeps a backlog of blocks waiting to go to tape, and you replay one night of its operation log. Each entry in ops is either "stage|1200|vol-7", which adds a run of that many blocks belonging to that volume to the back of the backlog, or "flush|500", which writes blocks from the front of the backlog until that many have been written or the backlog runs dry. Blocks are written in the order they were staged, and one run can be split across two flushes. A stage of zero blocks adds nothing at all. The same volume may be staged several times, and a flush that writes blocks from two runs of the same volume counts that volume once. A single run can hold up to a billion blocks. Return, for each flush in order, how many distinct volumes it wrote at least one block of.
volumes_per_flush(ops: list[str]) → list[int][["stage|3|vol-a","stage|2|vol-b","flush|4","flush|10"]]out[2,1][["stage|5|vol-a","stage|4|vol-a","flush|7","flush|0","flush|9"]]out[1,0,1][["flush|5","stage|0|vol-c","flush|2","stage|1|vol-c","flush|2"]]out[0,0,1]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[["stage|3|vol-a","stage|2|vol-b","flush|4","flush|10"]][2,1]not run yetsample[["stage|5|vol-a","stage|4|vol-a","flush|7","flush|0","flush|9"]][1,0,1]not run yetsample[["flush|5","stage|0|vol-c","flush|2","stage|1|vol-c","flush|2"]][0,0,1]not run yetsample