Code RoomCount peak power minutes
EasyPrep Room Coding #4812

Count peak power minutes

CodingAlgorithms & data structuresEntry–Mid~18 min

A plant pays a surcharge for every minute of the day when too many machines drew power at once, so the energy team needs that figure from the run log. runs holds one entry per machine run, written as [start, end] in minutes since midnight, and the run occupies the minutes start through end minus 1, so a run that ends exactly as another begins never shares a minute with it. The log is in no particular order, runs may overlap or repeat, and a cancelled run carries end equal to start. No end is earlier than its start. Return how many minutes had at least threshold runs going at the same time. Count each such minute once, however many runs cover it. When threshold is 0 or negative every minute would qualify, which bills nothing useful, so return 0.

Implement
high_demand_minutes(runs: list[list[int]], threshold: int) → int
Examples
in[[[540,600],[560,620],[610,660]],2]out50
in[[[0,30],[30,60],[10,20]],2]out10
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 18 min
InputExpectedGot
[[[540,600],[560,620],[610,660]],2]50not run yetsample
[[[0,30],[30,60],[10,20]],2]10not run yetsample