Trains the technique from
LeetCode 1893Check if All the Integers in a Range Are CoveredThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A depot numbers its patrol posts with consecutive integers. The night rota is given as shifts, where shifts[i] = [from_i, to_i] means guard i walks every post numbered from_i through to_i. Both ends of a walk are included, so a guard with [4, 4] walks post 4 and nothing else.
An auditor picks the span of posts numbered first through last, again including both ends, and wants to know whether the rota leaves no hole: every post in that span must be walked by at least one guard. Different guards may cover different parts of the span, and walks may overlap or sit side by side.
Return true if every post from first to last is walked by at least one guard, and false otherwise.
Example 1
The audited posts are 3, 4, 5, 6, 7 and 8. The first guard walks 3, 4 and 5, and the second walks 6, 7 and 8, so none of the six posts is left without a guard.
Example 2
Post 6 lies inside the audited span, but the first guard stops at post 5 and the second starts at post 7, so post 6 is walked by nobody.
Example 3
The audited span is the single post 8, and the only guard on the rota walks post 7 alone.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def posts_all_covered(shifts: list[list[int]], first: int, last: int) -> bool:public boolean postsAllCovered(int[][] shifts, int first, int last)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.