Signals

A latency percentile

Calculate a tail-latency statistic from a bounded batch of raw millisecond measurements.

In production

Tail latency on a page is only as honest as the percentile definition. A wrong rank quietly lies about p99.

What it must return

On a copy of the samples, return the nearest-rank value at ceil(p*n/100), or None when there are no samples.

  • Values are nonnegative numbers; 0 < p <= 100. Return sorted[ceil(p*n/100)-1]. Return None for no samples.
  • Do not mutate input values. Use the Python standard library only.

Edge cases

  • Empty input returns None.
  • Never sort the caller's list in place.
  • Nearest rank uses ceiling, then a zero-based index.

Signature

percentile(values, p)

Hints

  1. Second hint

  2. A partial sketch

The reference solution opens after the last hint.

solution.py · Python

Loading editor…

Median convention

values

[
  30,
  10,
  20,
  40
]

p

50

Expected

20

Each run uses a fresh Python runtime in this browser, with a 3-second limit and a Stop button. The first run downloads the runtime. 0 of 12 in Signals passed in Python on this device.

Next: Failures in a rolling window