The linear method: You create an array - one bool per minute. For one day 24 * 60 entries is enough. Spans (Start, End) are in minutes from midnight. Set array slots in range(Start, End) to True for each input span. Scan the array and find metaspans - contiguous sequences of False.