Non Overlapping Intervals
Return the fewest intervals to remove so that remaining intervals do not overlap. Touching endpoints are allowed.
Example 1
intervals = [[1,3],[2,4],[3,5]]1Explanation
Remove [2,4] and keep [1,3],[3,5]; touching at 3 is allowed.
Example 2
intervals = [[1,2],[2,3]]0Explanation
The intervals merely touch at 2, so no removal is needed.
Example 3
intervals = [[1,4],[1,4],[1,4]]2Explanation
Only one identical interval may remain, requiring two removals.
Constraints
- 1 <= number of intervals <= 100000
- Each interval has start < end
Function contract
eraseOverlapIntervalsArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[1,3],[2,4],[3,5]]