The Non-overlapping Intervals problem gives you a list of intervals and asks for the minimum number of intervals to remove so that the remaining intervals are non-overlapping. This Non-overlapping Intervals coding problem is the classic greedy interval scheduling problem, equivalent to finding the maximum number of non-overlapping intervals.
J.P. Morgan, Goldman Sachs, Microsoft, Meta, Amazon, Google, Bloomberg, and many others ask this because it's the canonical greedy interval scheduling problem. Solving it reveals whether candidates know the "earliest deadline first" greedy strategy — the fundamental insight for interval selection. The array, sorting, greedy, and dynamic programming interview pattern is the cornerstone here.
Sort by end time + greedy selection. Sort intervals by their end time. Greedily select intervals that don't overlap with the last selected: iterate through, keeping a lastEnd pointer. If the current interval starts ≥ lastEnd, select it (update lastEnd). Otherwise, it overlaps — skip it (count it as removed). Answer = total intervals - selected intervals.
Intervals: [[1,2],[2,3],[3,4],[1,3]]. Sort by end: [[1,2],[2,3],[1,3],[3,4]].
start < lastEnd (overlapping) vs start >= lastEnd (non-overlapping).The "earliest deadline first" greedy for interval scheduling is one of the most important algorithms in all of computer science. Memorize: sort by end time, greedily keep intervals that start after the last selected ends. The answer = total - kept. This same pattern solves "minimum meeting rooms needed" (sort starts and ends, two pointers) and "activity selection." Non-overlapping Intervals is the first problem to master when studying interval greedy algorithms.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Greatest Sum Divisible by Three | Medium | Solve | |
| Maximum Length of Pair Chain | Medium | Solve | |
| Reducing Dishes | Hard | Solve | |
| Minimize the Maximum Difference of Pairs | Medium | Solve | |
| Minimum Cost for Cutting Cake I | Medium | Solve |