Asked inMongoDB,Data Engineer-Intern

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...
MongoDB Data Engineer-Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter