I knew the two-pointer approach pretty quickly but fumbled the overlap condition on the first try.
Use a two-pointer technique to traverse both interval lists simultaneously, comparing the current intervals to find their intersection. At each step, advance the pointer of the interval that ends first, as it cannot intersect with any subsequent interval in the other list.
Pro tip: Clarify upfront that intervals are closed and non-overlapping, and confirm the expected output format (e.g., list of intervals). This shows attention to detail and avoids misinterpretation.
Restate the problem to ensure understanding: both lists are sorted, non-overlapping, closed intervals. Ask about output format and edge cases (e.g., empty lists, touching intervals).
Set two pointers, i and j, to 0, pointing to the first interval in each list. Prepare an empty result list.
While both pointers are within bounds, compute the intersection of the current intervals: start = max(start1, start2), end = min(end1, end2). If start <= end, add [start, end] to the result.
Move the pointer of the interval with the smaller end time forward. If ends are equal, advance both pointers.
After the loop, return the list of intersecting intervals.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.