Dsa
Intervals
Easy
Sensor Bridge
A motion sensor records active intervals [start, end]. However, the sensor is flaky: if the gap between two active intervals is less than or equal to G, we assume the sensor should have been active during the gap and 'bridge' them. Calculate the total duration of the final active intervals after bridging.
Example:
Input: N=2, G=10
Intervals: [10, 20], [25, 35]
Gap is 5 (<= 10), so bridge to [10, 35]. Total duration 25.
Key concepts
intervalsmergingsorting
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