Non-overlapping Intervals Problem
Non-overlapping Intervals Problem — ExecCode Medium DSA Practice
Solve the Non-overlapping Intervals problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an array of intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove so that the rest of the intervals are non-overlapping. Intervals that only touch at a single point, such as [1,2] and [2,3], are not considered overlapping.
Examples
Input intervals = [[1, 2], [2, 3], [3, 4], [1, 3]]; Output 1. Input intervals = [[1, 2], [1, 2], [1, 2]]; Output 2. Input intervals = [[1, 2], [2, 3]]; Output 0
Constraints
1 ≤ intervals.length ≤ 10⁵ intervals[i].length == 2 -5 × 10⁴ ≤ starti < endi ≤ 5 × 10⁴
Practice Non-overlapping Intervals free on ExecCode. Browse DSA problems, topic map, and placement guides.