You get a list of intervals. Remove as few of them as possible so that no two of the rest overlap, and return how many you removed. Intervals that only touch, like [1, 3] and [3, 5], do not overlap. Our example: [4, 7], [0, 9], [8, 11], [1, 3], [10, 12], [3, 5], [6, 8] — the answer is 3.
input
intervals: intervals [start, end] in any order; they may overlap, touch or repeat.
returns
The fewest intervals to remove so that no two of the rest overlap. Intervals that only touch, like [1, 3] and [3, 5], do not overlap.
constraints
1 ≤ intervals.length ≤ 10⁴
−5·10⁴ ≤ startᵢ < endᵢ ≤ 5·10⁴
our 11 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.