Trains the technique from
LeetCode 1288Remove Covered IntervalsThis 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 corridor camera writes one line into its log for every recording run. You are given windows, where windows[i] = [start_i, end_i] holds the minute mark at which run i began recording and the minute mark at which it stopped, with start_i < end_i.
Run a swallows run b when a began no later and stopped no earlier, that is a[0] <= b[0] and b[1] <= a[1].
Prune the log by deleting every run that is swallowed by some other run still listed, then return how many runs remain. No two lines of the log carry the same pair of minute marks, so no two runs swallow each other and the pruned count is well defined. The runs are in no particular order.
Example 1
Run [4, 7] is swallowed by [2, 9], since 2 <= 4 and 7 <= 9, so it is deleted. None of [2, 9], [3, 11] and [12, 15] is swallowed by another run, leaving 3 lines.
Example 2
Both [0, 2] and [0, 6] are swallowed by [0, 9], which began no later and stopped no earlier, so they are deleted and 1 line remains.
Example 3
Run [3, 7] begins later than [2, 7] and stops at the same mark, which satisfies 2 <= 3 and 7 <= 7, so it is deleted and 1 line remains.
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 count_surviving_windows(windows: list[list[int]]) -> int:public int countSurvivingWindows(int[][] windows)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.