All problems
Percentile Clip Threshold
Problem
Compute a percentile clipping threshold with linear interpolation: sort values, take rank = (percentile/100) * (n-1), and interpolate between the two neighboring order statistics. Clamp percentile to [0, 100]; a single value returns itself.
The signature is percentile_clip_threshold(values, percentile).
Hint
Percentile clipping trades a little range for much finer resolution near the bulk.
Test cases
case 1
in: [[1,2,3,4],50]
expected: 2.5
case 2
in: [[1,2,3,4],25]
expected: 1.75
case 3
in: [[1,2,3,4],100]
expected: 4
case 4
in: [[5],90]
expected: 5
case 5
in: [[0,10],10]
expected: 1
Starter codePython
import math
def percentile_clip_threshold(values, percentile):
# Your code here
pass5 test cases · run your code against them in the editor