Code RoomPercentile latency
MediumPrep Room Coding #499

Percentile latency

CodingAlgorithms & data structuresEntry–Mid~14 min

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) → int
Examples
in[[120,200,90,500,150],95]out500
What 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
InputExpectedGot
[[120,200,90,500,150],95]500not run yetsample