Intervals
47 / 170IntervalsLesson 1 of 6About 29 min
Get the overlap test exactly right, including whether touching counts, and most of this unit follows.
Sort by start or by end. Make one pass. Compare each interval against something you are carrying: the previous interval, the current merged block, the last end you accepted.
The problem below is the smallest version: sort by start, and check whether any interval begins before its predecessor finishes.
Two overlap tests differing only in strictness, applied to intervals that touch. Type the two values separated by a space.
def overlaps_strict(first, second): return first[0] < second[1] and second[0] < first[1] def overlaps_closed(first, second): return first[0] <= second[1] and second[0] <= first[1] print(overlaps_strict([1, 4], [4, 6]), overlaps_closed([1, 4], [4, 6]))Read the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.