An interval is two numbers: a start and an end (a meeting, a booking). Nearly every question about intervals begins with the same step: sort by start. After sorting, an interval either clashes with the one just before it or it does not; there is no need to look further away.
ordered = sorted(intervals)blocks = [ordered[0][:]]for start, end in ordered[1:]:if start <= blocks[-1][1]:blocks[-1][1] = max(blocks[-1][1], end)else:blocks.append([start, end])
max is essential: a short interval inside must not pull the block's end back."Is there a clash?" is a simpler form of this: in the sorted list, an interval that starts before the previous one ends is a clash. Sorting a list of pairs looks at the start first by itself, and at the end on a tie.