cs-070 — The Meeting Merge
| Field | Value |
|---|---|
| id | cs-070 |
| difficulty | Foundational |
| topics | sorting, intervals |
| lecture | lecture-18 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | lectures 1-2 (problem framing, precise pseudocode) |
| objective | recognise the pattern, translate it into precise steps, and trace it correctly |
| solution | held by the instructor; discussed after the attempt |
Problem
Merge overlapping meeting intervals. Sort first, then single scan with a merge rule; why sorting makes the scan trivial.
Your deliverable is the answer for the worked instance, the precondition stated, and the not-found behaviour demonstrated. If the problem is ambiguous anywhere, state the assumption you are making and carry on — a stated assumption is part of a good answer.
Examples
- Input: meetings [(1,4), (2,3), (5,7), (6,8)]
- Output: merged: [(1,4), (5,8)]; (2,3) inside (1,4); (6,8) overlaps (5,7)
Solve for the worked instance first. Then ask what would change if one number, name, or condition were replaced by something stranger.
What to notice
- Sort by start; then one pass: if next.start <= current.end, extend; else push and continue.
- Sorted data is not just faster — it enables different algorithms.
- A scan is only as good as its stated precondition.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "If this scan ran 10,000 times a day, what would you precompute?"
Constraints and assumptions
- Difficulty: Foundational (early-semester techniques assumed: precise statements, traces, simple loops).
- Topics: sorting, intervals.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes; naming the pattern and stating the assumption is already a pass, completing the calculation is the stretch.
- Optional stretch (not required): describe an alternative approach and say when it beats the obvious one.
Hints and extension
- First nudge: identify the pattern the worked instance uses before computing anything.
- If stuck after three minutes, write the input/output line you expect and trace the smallest example by hand.
- After the reveal, attempt the extension below before the next lecture.
- Extension challenge: Add a stable tie-break rule and show a case where it matters.