# Maximal set of overlapping intervals | {Coding Question}

## Given a collection of intervals, return a maximal set of non-overlapping intervals while prioritizing the longer intervals.

input — (1,5),(2,7),(11,18)

output — (11, 18), (2, 7)

In the given example, (1,5) and (2,7) are overlapping intervals and while choosing between the two, (2,7) is chosen as 7–2 > 5–1.

Time complexity: O(N logN)

Space Complexity: O(N)