Code RoomService with highest error rate
MediumPrep Room Coding #495

Service with highest error rate

CodingAlgorithms & data structuresEntry–Mid~15 min

Each line of a platform log has the form "<timestamp> <LEVEL> <service> <message>". A service's error rate is the number of its ERROR lines divided by its total lines. Given at least one line, return the name of the service with the highest error rate. If several services tie on rate, return the alphabetically smallest name among them. Prefer exact integer arithmetic over floating-point division — rates like 1/3 do not compare cleanly as floats.

Implement
worst_error_service(lines: list[str]) → str
Examples
in[["t1 ERROR auth login failed","t2 INFO auth ok","t3 ERROR billing charge failed","t4 ERROR billing retry failed","t5 INFO search ok"]]out"billing"
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 15 min
InputExpectedGot
[["t1 ERROR auth login failed","t2 INFO auth ok","t3 ERROR billing charge failed","t4 ERROR billing retry failed","t5 INFO search ok"]]"billing"not run yetsample