Each line of an access log reads "<timestamp> <method> <path> <status> <latency_ms>", separated by spaces. Write slow_endpoints(lines, threshold_ms) returning the endpoints, written "METHOD /path", whose 95th percentile latency is above threshold_ms, slowest first (endpoints with the same p95 in alphabetical order). An endpoint's path does not include its query string: /search?q=a is /search. Use the nearest-rank percentile: sort the endpoint's latencies and take the one at position ceil(0.95 * n), counting from 1. Skip any line that does not have exactly five fields.
Example
slow_endpoints(["2025-03-01T10:00:00 GET /feed 200 120", "2025-03-01T10:00:01 GET /feed 200 480", "2025-03-01T10:00:02 POST /share 201 90", "2025-03-01T10:00:03 GET /feed 200 150"], 200)
['GET /feed']
What this question tests
Tests log parsing and a percentile done by hand: malformed lines, query strings that belong to their path, and the exact definition of p95. Monitoring questions like this are common for data and infrastructure engineers because the right answer depends on reading the definition rather than reaching for a library default.
More Python interview questions