Percentile latency
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.
Implement
percentile_latency(latencies: list[int], p: int) → intExamples
in
[[120,200,90,500,150],95]out500What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 14 min
solution.py
InputExpectedGot
[[120,200,90,500,150],95]500not run yetsample