Code RoomUnion of intervals length
EasyPrep Room Coding #656

Union of intervals length

CodingAlgorithms & data structuresEntry–Mid~12 min

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]]) → int
Examples
in[[[0,30],[20,50],[70,80]]]out60
What 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
InputExpectedGot
[[[0,30],[20,50],[70,80]]]60not run yetsample