Merge Overlapping Intervals Problem Statement
You are given 'N' intervals, each defined by two integers, marking its boundaries. Your task is to merge all overlapping intervals and return a list of merged intervals sorted in ascending order.
Example:
Input:
5
start: [1, 3, 6, 10, 8]
end: [4, 5, 8, 12, 9]
Output:
[1, 5]
[6, 9]
[10, 12]
Explanation:
Intervals [1,4] and [3,5] overlap and merge into [1,5]. Similarly, [6,8] and [8,9] overlap and merge into [6,9]. [10,12] does not overlap with any other interval.
Input:
Input consists of multiple test cases. Each test case starts with a line containing an integer 'N', the number of intervals. The next line contains 'N' starting integers. The following line contains 'N' ending integers.
Output:
For each test case, print the merged intervals, each specified by two space-separated integers (start end) per line. Output each test case result on a new line.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
0 ≤ start, finish ≤ 10^9
- Duration per test case: 1 second
Be the first one to answer
Add answer anonymously...
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

