Practice Discrete Math

Algorithms / Interval Scheduling Greedy

Least You Need to Know: Interval Scheduling and Earliest-Finish Greedy

For maximizing how many non-overlapping intervals you can keep, the standard greedy rule is to sort by **earliest finishing time** and repeatedly accept the next compatible interval. The reason is that earlier finishes preserve more room for future choices.

The least you need to know

Key notation

[s, f) interval with start s and finish f
current_end finish time of last accepted interval
compatible new interval starts after or at current_end

Tiny worked example

  • Sort intervals by finishing time.
  • Accept the first interval.
  • Track the finish time of the last accepted interval.
  • Scan left to right and accept the next interval whose start is at least that finish time.

Common mistakes

How to recognize this kind of problem

Start practice