Worker uptime total
A cron supervisor logs "<ts> START" when a worker comes up and "<ts> STOP" when it goes down, with ts as integer Unix seconds. The log is chronological and well-formed: events strictly alternate beginning with START, so a STOP always closes the most recent START. Given the log and the current time now (now >= every logged ts), return the worker's total uptime in seconds. If the log ends with a START, the final run is still going and counts up to now. An empty log means zero uptime.
Implement
total_uptime(events: list[str], now: int) → intExamples
in
[["100 START","250 STOP","300 START"],400]out250What 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 13 min
solution.py
InputExpectedGot
[["100 START","250 STOP","300 START"],400]250not run yetsample