Service with highest error rate

Write codeMedium15 min

Your task

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.

Examples

worst_error_service(lines: list[str]) -> str
Example 1
Inputworst_error_service(["t1 ERROR auth login failed", "t2 INFO auth ok", "t3 ERROR billing charge failed", "t4 ERROR billing retry failed", "t5 INFO search ok"])
Output"billing"