A calibration rig records n readings from a sensor, where n is guaranteed to be a multiple of 20 so that exactly 5% of the readings falls on each side. Before trusting the sensor, an engineer discards outliers: the smallest 5% of the readings and the largest 5% of the readings (by sorted position) are both removed, and the arithmetic mean of the remaining readings is reported as the calibrated value. Given the readings, compute this trimmed mean.
Print a single line containing the trimmed mean, rounded to exactly 5 digits after the decimal point.
Example 1
Input
20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Expected
10.50000
Explanation
n=20 so 1 reading (5%) is trimmed from each end. Removing the smallest (1) and the largest (20) leaves 2..19, which sums to 189 over 18 values, giving a mean of 10.50000.
Example 2
Input
40 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
Expected
20.50000
Explanation
n=40 so 2 readings (5%) are trimmed from each end. Removing {1,2} and {39,40} leaves 3..38, which sums to 738 over 36 values, giving a mean of 20.50000.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →