Union of intervals length

Write codeEasy12 min

Your task

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.

Examples

total_on_minutes(sessions: list[list[int]]) -> int
Example 1
Inputtotal_on_minutes([[0, 30], [20, 50], [70, 80]])
Output60