Interval list intersections
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.
0:00 of about 25 min
solution.py
InputExpectedGot
[[[0,2],[5,10],[13,23],[24,25]],[[1,5],[8,12],[15,24],[25,26]]][[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]not run yetsample