Latency Percentiles
A dashboard reports p50, p95 and p99 response times. Use the nearest-rank method: sort the samples (milliseconds) ascending; for percentile p the rank is Math.ceil(p * n / 100) (at least 1), and the answer is the sample at that 1-based rank.
Return an array with one value per entry of percentiles, in the same order. If there are no samples, every value is null.
Example 1
Input: samples = [120,80,95,300,110,105,90,85,100,1000], percentiles = [50,90] Output: [100,300] Explanation: n = 10: p50 is rank 5 and p90 rank 9.
Example 2
Input: samples = [5], percentiles = [50,99,100] Output: [5,5,5]
Constraints
- 0 <= samples.length <= 10^5
- 1 <= percentiles.length <= 10
- Each percentile is an integer from 1 to 100
Hint 1
Sort numbers with (a, b) => a - b; the default sort compares strings.
Hint 2
Compute p * n before dividing by 100 so the rank is exact.
Good practice for: Site Reliability Engineer, DevOps Engineer, Cloud Engineer, Backend Developer, MLOps Engineer, Data Engineer
Run checks your code on 3 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.