Closed nights include both ends, so the next stay starts the night after
Meetings end at an instant. Hotel stays are counted in whole nights, and that changes what the end means.
Predict
A stay covers nights 10 through 12, closed. What's the first night the next stay can start?
Closed nights
nights
101112131415(10, 12)xxx(13, 15)xxx
(10, 12) holds nights 10, 11 and 12. The next stay starts on night 13.
A stay from night 10 through night 12 is nights 10, 11 and 12. That's a closed interval: both ends are in. It's written (10, 12), and its length is end - start + 1, 3 here.
Closed fits things you count whole, like nights and days, when the question says through. Back to back here means the next stay starts the night after. (10, 12) and (13, 15) cover 10 through 15 with no gap.
A closed run of integers (a, b) is the half-open (a, b + 1), so you can always convert. In the figure, (10, 12) covers nights 10 through 12, the same nights as a half-open (10, 13).
Pick one kind of end per problem, say it out loud, and write every comparison for that one:
Closed (a, b)
Half-open (a, b)
Holds
a <= t <= b
a <= t < b
Length
b - a + 1
b - a
Back to back with (c, d)
c == b + 1
c == b
Overlaps (c, d)
a <= d and c <= b
a < d and c < b
In the editor, write nights(stay) and back_to_back(a, b) for closed stays: how many nights a stay holds, and whether b starts the night after a ends.
Pick an answer above to see the rest
Instructions
1
Write nights(stay): how many nights the closed (first, last) holds, both included.
2
Write back_to_back(a, b): true when stay b starts the night after stay a ends.