Question bank › Intervals
Dsa Intervals Easy

Interval Coverage

You are given several intervals represented as pairs of integers [start, end]. Your task is to determine how much of the number line is covered by at least one of the intervals. The coverage is defined as the total length of the segments covered by at least one interval. Input format: - First line contains an integer n (1 ≤ n ≤ 100): number of intervals. - Next n lines each containing two integers start and end, separated by a space (0 ≤ start < end ≤ 10^9). Output format: - Print a single integer representing the total length covered by at least one interval. Example: Input: 3 1 3 2 4 5 7 Output: 6

Key concepts

intervalscoveragecounting

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 InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.