Question bank › Intervals
Dsa Intervals Medium

Merge Interval Gaps

Given a list of intervals, merge all overlapping intervals and return the list of merged intervals, as well as the total gaps (intervals formed between merged ones). Input Format: - The first line contains an integer n, representing the number of intervals. - The next n lines each contain two integers, l and r, representing the start and end of an interval. Output Format: - Print a list of merged intervals followed by the total number of gaps as a tuple. Example: Input: 5 1 3 2 5 6 8 7 9 10 12 Output: [(1, 5), (6, 9), (10, 12)], 1

Key concepts

intervalsmerginggreedy

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.