Percentile latency
Your task
Your dashboard reports tail latency using the nearest-rank method. Given a non-empty list of request latencies in milliseconds (integers, any order) and a percentile p between 1 and 100, sort the latencies ascending and return the value at rank ceil(p * n / 100), where n is the count and ranks start at 1. For example, p = 95 over 5 values selects rank 5. Return the latency as an integer, no interpolation between values.
Examples
percentile_latency(latencies: list[int], p: int) -> intExample 1
Input
percentile_latency([120, 200, 90, 500, 150], 95)Output
500