Dsa
Intervals
Easy
Interval Summation
Write a program that takes a list of intervals and calculates the total length of all intervals after merging overlapping ones. Each interval is defined by a start and end time. The output should be the total length of all merged intervals.
Input format:
- The first line contains an integer n, the number of intervals.
- Each of the next n lines contains two integers, start and end, separated by a space.
Output format:
- Print the total length as an integer.
Example:
Input:
4
1 4
2 5
7 9
8 10
Output:
7
Key concepts
intervalssummationmerging
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