PIXELBANKv9.1.0
Menu

Non-overlapping Intervals

Given intervals [start, end], return the minimum number of intervals to remove to make the rest non-overlapping.

Input: intervals as start:end comma-separated.

Example:

Input:
1:2,2:3,3:4,1:3
Output:
1
Reasoning:
  • The given intervals are [1,2], [2,3], [3,4], and [1,3], which can be sorted by their end values as [1,2], [2,3], [3,4], and [1,3].
  • After sorting, we can see that [1,3] overlaps with [1,2] and [2,3], but if we remove [1,3], the remaining intervals are non-overlapping.
  • The number of intervals to remove is 11, as removing [1,3] makes the rest non-overlapping.
  • The final output is 11, which is the minimum number of intervals to remove.

Constraints:

  • 1 <= len(intervals) <= 10^5
  • -5 * 10^4 <= start < end <= 5 * 10^4
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.