A courier has accepted delivery windows, each a closed interval [start, end] in minutes. Two windows conflict when they share at least one minute, so [1, 3] and [3, 5] conflict. Return the minimum number of windows to cancel so that no two remaining windows conflict.
Examples
Input: windows = [[1, 3], [2, 4], [3, 5], [6, 8]]
Output: 2
Explanation: Keep [1, 3] and [6, 8] (or [2, 4] and [6, 8]); no three windows are pairwise free of conflicts.
Input: windows = [[1, 2], [3, 4], [5, 6]]
Output: 0
Constraints
0 <= len(windows) <= 5 * 10**4,0 <= start <= end <= 10**9.- Closed intervals: sharing a single minute is a conflict.
- Target complexity: O(n log n).
Goals
- Recognise that minimising removals is the same as maximising what you keep
- Apply the closed-interval rule where touching windows conflict