InferenceAI

Enter at least two characters to search.

Start free

Fewest Overlap Removals

mediumGreedy & Intervals25 min25 XP

Return the minimum number of intervals to remove so the remaining intervals don't overlap. Intervals that only touch, like [1, 2] and [2, 3], don't overlap.

Examples

EXAMPLE WALKTHROUGHremove one

A guided view of the published example, not a trace of your code.

INPUT[[[1,2],[2,3],[3,4],[1,3]]]
TASKfewest_overlap_removals()
EXPECTED OUTPUT1

Start with the input values shown in this example.

Example 1 of 3

Input: intervals = [[1,2],[2,3],[3,4],[1,3]]

Output: 1

Explanation: remove one

Input: intervals = [[1,2],[1,2],[1,2]]

Output: 2

Explanation: duplicates

Input: intervals = [[1,2],[2,3]]

Output: 0

Explanation: touching

Hint 1

Sort by end time and keep each interval that starts at or after the last kept end.

Topics

DSAGreedy & IntervalsPython