I jumped straight into sort-and-merge without asking about the endpoints first, which came back to bite me when they asked me to verify my calculation.
First, clarify that intervals are inclusive and may overlap. Then, sort intervals by start time and merge overlapping intervals, summing the lengths of merged intervals to get total running time. Alternatively, use a sweep line with events to count active processes.
Pro tip: Mention that sorting is O(n log n) and that the merge approach is optimal; also note that if intervals are already sorted, a single pass suffices. This shows awareness of input assumptions and efficiency.
Confirm that intervals are inclusive, may overlap, and that we need total time with at least one process running. Discuss edge cases like empty input, single interval, and touching intervals (e.g., [1,2] and [2,3] overlap at point 2).
Decide between sorting and merging intervals or using a sweep line with events. Both are valid; sorting is simpler and O(n log n). Explain the trade-offs.
For sorting: sort by start, then iterate, merging overlapping intervals and accumulating lengths. For sweep line: create events (start +1, end -1), sort, and track active count to sum durations where count > 0.
State time complexity O(n log n) due to sorting, space O(n) for sorting or O(1) extra if in-place. Walk through a small example to verify correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.