Percentile Calculation

Medium
statistics JPMorgan Goldman Sachs

Compute the p-th percentile of a list of numbers using linear interpolation.

Example

percentile([15, 20, 35, 40, 50], 40)
# => 27.0

Use the formula: index = (p/100) * (n-1), then interpolate between the two surrounding values.

Test Cases

Python Editor

Output

Click "Run" to see results...