38/42
Part 8 of 8 · Follow-upsLearn and do
The fewest stays for a longer trip is the fewest-shifts greedy
No pair covers the range, so find the fewest stays. Every listing's runs within the trip are closed intervals. The fewest stays that cover the trip is fewest_shifts on all of them, and the moves are one fewer than the stays.
The cheapest among the fewest stays is a different question, and the greedy can't answer it. That takes a table over the nights.
In the editor, runs and fewest_shifts are filled in, and TRIP maps each listing to its free nights. Write fewest_moves(listings, start, end): every listing's runs go to fewest_shifts, and the moves are one fewer than the stays.