Percentile
EasyStatisticsMathArraySorting
Description
Given an array of numbers and a percentile p between 0 and 100, return the p-th percentile using linear interpolation: sort the data, compute the rank index p/100 * (n - 1), and interpolate linearly between the two nearest sorted values. Round the result to 4 decimal places.
Examples
Input:
[1,2,3,4,5], 50Output:
3Explanation:
The rank index lands between two sorted values, and linear interpolation between those neighbours gives the requested percentile.
Input:
[1,2,3,4], 25Output:
1.75Explanation:
The rank index lands between two sorted values, and linear interpolation between those neighbours gives the requested percentile.
Input:
[10,20,30,40], 90Output:
37Explanation:
The rank index lands between two sorted values, and linear interpolation between those neighbours gives the requested percentile.
Constraints
- •
1 ≤ array length ≤ 10⁴ - •
0 ≤ p ≤ 100