Code RoomService failure streak detection
MediumPrep Room Coding #496

Service failure streak detection

CodingAlgorithms & data structuresEntry–Mid~13 min

A health checker appends one line per probe: "<timestamp> <service> <status>", where status is "ok" or "fail". An incident page should fire when any single service fails n times in a row — counting only that service's own probes, in log order; probes of other services in between do not reset the streak. Given the log lines and n (n >= 1), return true if some service reaches n consecutive "fail" probes, and false otherwise.

Implement
has_consecutive_failures(lines: list[str], n: int) → bool
Examples
in[["t1 db fail","t2 db fail","t3 api ok","t4 db fail"],3]outtrue
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
[["t1 db fail","t2 db fail","t3 api ok","t4 db fail"],3]truenot run yetsample