Averages hide tail behavior: a service with a 50ms average latency can still have some users waiting 2 seconds. Given a list of per-request latency measurements, compute the P50 (median), P95, and P99 latency percentiles using linear interpolation between the two nearest ranks — the standard method reported by serving dashboards.
rank = p/100 * (n - 1)
percentile = sorted[floor(rank)] + (rank - floor(rank)) * (sorted[ceil(rank)] - sorted[floor(rank)])
(n-1)-based linear interpolation rank formula, not the (n+1)-based or nearest-rank method.n == 1 (all percentiles equal the single sample).Sort the array once, then just index it with int(rank) and int(rank)+1 (clip the upper index to the last valid index) for each requested percentile — no need to re-sort per percentile.
No results yet
Run your code to check it against the examples, or submit to run every test.