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

Question

A status probe writes one line per check as "<ts> <status>", where ts is integer Unix seconds (chronological) and status is "up" or "down". Postmortems need time-to-recover: find the FIRST "down" line, then the first "up" line after it, and return the difference in seconds between those two timestamps. If the service never went down, return 0. If it went down and no later "up" line exists, return -1.

Implement
recovery_seconds(lines: list[str]) → int
Examples
in[["100 up","160 down","220 down","300 up"]]out140
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.