Code Room
CodingMediumcod-g854
Subject IntervalsLevel Mid–Senior~25 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You are given two lists of closed intervals, A and B, each pairwise-disjoint and sorted by start. Return the list of intervals representing their intersection, sorted by start. Each output interval [lo, hi] is a maximal range present in BOTH inputs (lo == hi is allowed when they touch at a single point).

Implement
interval_intersection(A: list[list[int]], B: list[list[int]]) → list[list[int]]
Examples
in[[[0,2],[5,10],[13,23],[24,25]],[[1,5],[8,12],[15,24],[25,26]]]out[[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.