Code Room
CodingMediumcod-g1316
Subject Log processingLevel Entry–Mid~13 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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) → int
Examples
in[["100 START","250 STOP","300 START"],400]out250
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.