Dsa
Greedy
Medium
Efficient Pipeline Layout
You are designing a pipeline system that connects multiple water sources, represented by intervals on a line. Each interval has a start and end point. Your task is to find the minimum length of pipe required to connect all sources without overlaps. You can overlap pipes but aim to minimize the total length used. Given the intervals, return the minimum length of pipe required to connect all sources.
Input Format:
- The first line contains an integer n (1 ≤ n ≤ 100) - the number of intervals.
- The following n lines each contain two space-separated integers representing the start and end of each interval.
Output Format:
- A single integer - the minimum length of pipe required.
Example:
Input:
3
1 4
2 5
6 8
Output:
6
Key concepts
greedyintervalsoptimization
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