Paint alert timeline

Write codeMedium25 min

Your task

A monitoring console paints one incident timeline for the whole fleet. Alert i is raised at starts[i] and clears at ends[i], covering every minute from starts[i] up to but not including ends[i], and carries a severity levels[i] between 1 and level_count. Where several alerts overlap, the console paints only the highest severity present, so a milder alert underneath contributes nothing. The alerts arrive in no particular order, an alert with equal bounds covers nothing, and minute stamps are counted from a fixed epoch so they can be negative. Timestamps reach a billion either way, so painting the timeline minute by minute is out. Return a list of length level_count where position j holds the count of minutes painted at severity j plus 1. Minutes carrying no alert are painted at no severity and belong nowhere.

Examples

top_severity_minutes(starts: list[int], ends: list[int], levels: list[int], level_count: int) -> list[int]
Example 1
Inputtop_severity_minutes([0, 10, 30], [20, 40, 35], [1, 2, 3], 3)
Output[10, 25, 5]
Example 2
Inputtop_severity_minutes([0, 5, 10], [5, 10, 15], [3, 1, 2], 3)
Output[5, 5, 5]
Example 3
Inputtop_severity_minutes([0, 0], [10, 10], [1, 3], 3)
Output[0, 0, 10]