32/42
Part 7 of 8 · The worked exampleLearn and do

On closed days the test is covered + 1, and covered starts at start - 1

shifts[i][0] <= covered + 1 is the closed-days rule from the handoffs. A shift that starts the day after the covered stretch ends continues it. Two slips break it:

  • Write <= covered, and the first round looks for shifts that start by day 0. It finds none, and returns -1 for a rotation that three shifts cover.
  • Start covered at start instead of start - 1, and day 1 counts as covered before any shift is chosen. That version returned 2.

With half-open hours, where (1, 5) covers up to the instant 5, covered starts at start and the test is <= covered.

In the editor, fewest_blocks(blocks, start, end) is the cover for closed days. Change it for half-open hours, where a block that starts as another ends continues it.