Which microservices are on fire?
The on-call engineer of a Berlin fintech gets a dump of log lines and wants to know which services have an unhealthy error rate. Each line looks like 2026-03-14 09:15:02 [ERROR] checkout: Payment gateway timeout: a date, a time, the level in square brackets, the service name, a colon, and a free-text message.
- The level is the first bracketed word of the line and may be written in any case. Levels
ERRORandFATALcount as errors; everything else (INFO, WARN, DEBUG) does not. - The service name is the text between
]and the first colon after it. Names are case-sensitive. The message may contain colons or more brackets, which must be ignored.
Task: line 1 is an integer threshold T (percent). Line 2 is the number of log lines N. Then come N log lines. A service is unhealthy when errors * 100 >= T * total (total = all its lines). Print each unhealthy service as service: E/total (R%) where R is E*100/total with one decimal. Sort by rate descending, services with exactly equal rates by name ascending. If no service is unhealthy print All services healthy.
Sample tests
Input
30 8 2026-03-14 09:15:02 [ERROR] checkout: Payment gateway timeout 2026-03-14 09:15:05 [INFO] checkout: Order 4411 created 2026-03-14 09:16:00 [info] search: Query ok 2026-03-14 09:16:10 [WARN] search: slow response: 2300ms 2026-03-14 09:17:00 [Error] auth: Token store down 2026-03-14 09:17:01 [FATAL] auth: Cannot reach redis [retrying] 2026-03-14 09:18:00 [INFO] auth: Login ok 2026-03-14 09:19:00 [DEBUG] checkout: cache warm
Expected output
auth: 2/3 (66.7%) checkout: 1/3 (33.3%)
Input
90 2 2026-01-01 00:00:01 [INFO] api: start 2026-01-01 00:00:02 [ERROR] api: boom
Expected output
All services healthy
Your answer is also checked against 3 hidden tests.
Need a hint?
Fractions like 1/3 and 2/6 are exactly equal when you compare them as numbers, so they are ties.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
