The Boxplot Numbers
Halden Analytics draws a boxplot for every metric on its dashboard. The box is the middle half of the data: it begins at the lower quartile, a quarter of the way up the ordered values, and ends at the upper quartile, three quarters of the way up. The width of that box is the interquartile range, and the dashboard trusts it as its spread number because, unlike the full range, one freak value cannot move it.
Quartiles have several competing definitions, so this dashboard pins one down. It uses the exclusive-median convention: the lower quartile is the median of the values lying below the overall median, the upper quartile is the median of the values lying above it, and when the count is odd the overall median itself belongs to neither half.
Task: Print the interquartile range of the values.
Input
The first line holds one integer n, how many values follow; n is at least 4. Each of the next n lines holds one value as a plain number. The values are not sorted.
Output
One line holding the interquartile range with exactly one digit after the decimal point.
Example:
Input:
7
1
2
3
4
5
6
7
Output:
4.0
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in