Code RoomService recovery time
MediumPrep Room Coding #510

Service recovery time

CodingAlgorithms & data structuresEntry–Mid~13 min

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.

0:00 of about 13 min
InputExpectedGot
[["100 up","160 down","220 down","300 up"]]140not run yetsample