Interval list intersections
You are given two lists of closed intervals, A and B, each already sorted by start and each internally disjoint (no two intervals within the same list overlap). Return the list of all intersections between an interval of A and an interval of B, as closed intervals, sorted by start. A point-overlap like [5,5] is a valid intersection. Either list may be empty.
Implement
interval_intersections(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