Code Room
CodingEasycod-g1456
Subject IntervalsLevel Entry–Mid~12 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.