Code Room
CodingMediumcod-g1312
Subject Log processingLevel Entry–Mid~14 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.