Skip to content
BytePatterns

Drop Spans Covered by Others

MediumIntervals#intervals#sort-by-start~20m

Problem

A monitoring system has a list of alert windows [start, end]. A window is redundant when another window in the list covers it completely, meaning the other one starts no later and ends no earlier. Remove every redundant window and return how many remain. No two windows in the list are identical.

Examples

Input:  spans = [[1, 4], [3, 6], [2, 8]]
Output: 2
Why:    [3, 6] lies inside [2, 8]; [1, 4] and [2, 8] only overlap
Input:  spans = [[1, 2], [1, 4], [3, 4]]
Output: 1
Why:    [1, 4] covers both others, including the two that share an endpoint with it
Input:  spans = [[3, 5]]
Output: 1
Why:    edge case, a lone window has nothing to cover it

Hints

0 / 3

Stuck on the idea rather than the code? Interval Basics & Sorting covers it.