Greedy interval scheduling

Which intervals does earliest finish select?

Examples

Worked example

Input
[1,4), [2,3), [3,5)
Expected output
[2,3) and [3,5)

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

The interval ending at 3 is selected first. The next one starts exactly when it ends.

Back to the lesson