Algorithm · ByteDance · Medium
Implement interval_intersection(firstList, secondList). Each argument is a list of closed intervals [start, end]: firstList plays the role of list A (holding m intervals) and secondList plays the role of list B (holding n intervals). Inside either list, the intervals are ordered by their start values and no two of them overlap. Return every interval that lies in the overlap of some interval from A with some interval from B, ordered by start value. Because the intervals are…