Maximum Movies You Can Watch
Problem Given a list of movies each with a start and an end time, find the maximum number of movies you can watch such that no two of them overlap.
Input / Output
- Input: a list of n intervals (start_i, end_i).
- Output: an integer — the largest possible count of mutually non-overlapping movies (extension: the actual schedule chosen).
Constraints
- 1 <= n <= 10^5; times may overlap arbitrarily.
- Clarify whether a movie ending exactly when another starts counts as a conflict — usually it does not, which makes the check
start >= lastEndrather than>. - Movie length and desirability are irrelevant here; only the count is being maximised.
Example
[(1,3),(2,4),(3,5),(6,8)]→ 3, e.g. (1,3), (3,5), (6,8).[(1,10),(2,3),(4,5),(6,7)]→ 3. Sorting by start time picks the long (1,10) first and yields only 1 — the counterexample that rules out the obvious alternative sort key.
asked …