Question bank › Intervals
Dsa Intervals Easy

Dual-Lamps Street

A straight street is illuminated by N lamps. Each lamp $i$ covers the interval $[S_i, E_i]$. Maintenance crews want to know which parts of the street are 'redundantly lit' by exactly two lamps. Calculate the total length of the street that is covered by exactly two overlapping lamp ranges. Input Format: - An integer N (number of lamps). - N lines, each containing two integers S and E. Output Format: - A single integer representing the total length covered by exactly 2 lamps. Example: Input: 3 1 10 5 15 8 20 Output: 8 Explanation: Range 1-5 (1 lamp), 5-8 (2 lamps), 8-10 (3 lamps), 10-15 (2 lamps), 15-20 (1 lamp). The exactly-two ranges are [5,8] and [10,15], length 3 + 5 = 8.

Key concepts

sweep-lineintervalscoordinate-processing

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.