What is the activity selection / interval scheduling problem?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

The Activity Selection problem: given n activities with start and end times, select the maximum number of non-overlapping activities. Greedy solution: (1) Sort activities by end time; (2) Select the first activity; (3) For each subsequent activity, select it if its start time ≥ the end time of the last selected activity. Greedy proof: always selecting the activity that ends earliest leaves maximum time for remaining activities. Time: O(n log n) for sorting + O(n) for selection. Applications: (1) Classroom/meeting room scheduling; (2) Processor task scheduling; (3) Bandwidth allocation. Related problems: Minimum meeting rooms: find the minimum number of meeting rooms needed to schedule all meetings. Greedy with a min-heap: sort by start time, for each meeting, if earliest-ending room is free (heap.peek().end ≤ current.start), reuse it; otherwise add a new room. Answer = max heap size. O(n log n). Interval merging: merge all overlapping intervals. Sort by start, iterate merging overlapping pairs. O(n log n). Non-overlapping intervals (minimum removals): n - maximum non-overlapping intervals = minimum to remove. Activity selection problems are the canonical greedy algorithm examples, demonstrating that greedy works when optimal substructure + greedy choice property hold.

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.