Union of intervals length
A smart plug logs every session a space heater was switched on as [start, end] minute pairs, occupying the half-open span [start, end). Several sensors report independently, so sessions may overlap or even duplicate. Return the total number of minutes the heater was actually on. Example: [[0,30],[20,50],[70,80]] gives 60.
Implement
total_on_minutes(sessions: list[list[int]]) → intExamples
in
[[[0,30],[20,50],[70,80]]]out60What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 12 min
solution.py
InputExpectedGot
[[[0,30],[20,50],[70,80]]]60not run yetsample