Question
Given intervals `[start, end]`, remove as few as possible so that the remaining intervals do not overlap. Intervals that only touch at an endpoint are compatible. ```python def min_removals_for_non_overlap(intervals: list[list[int]]) -> int: ... ``` Assume every interval satisfies `start <= end`. The input may be unsorted and may contain duplicates. Target `O(n log n)` time. ## Staged follow-ups 1. Return the retained or removed interval indices. 2. Assign positive weights and maximize retained weight rather than retained count. 3. Handle online arrivals and explain which guarantees can no longer be optimal.