What is the merge overlapping intervals problem?
In the merge overlapping intervals problem, we are given a group of time intervals and tasked with outputting mutually exclusive intervals.
Algorithm
The most efficient way to solve this problem is to use the stack structure:
- Sort the given list of time intervals in ascending order of starting time.
- Then, push the first time interval in the stack and compare the next interval with the one in the stack.
- If it’s overlapping, then merge them into one interval; otherwise, push it in the stack.
- In the end, the intervals left in the stack will be mutually exclusive.
1 of 7
Time Complexity
The naive approach would be to compare each interval with all the other intervals in the list; this approach would take time. However, as mentioned above, the efficient approach would take time because we have to sort n intervals making it time complexity.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved