Detecting Outliers With the IQR
Riverbend Supply screens supplier invoices for suspiciously large amounts before they go for approval. The screen uses the standard box-plot rule, and only its high end — an unusually cheap invoice is nobody's problem. The rule works from the middle half of the invoices: the amount a quarter of the way along the sorted invoices, and the amount three quarters of the way along. Where either point falls between two invoices, those two are blended in proportion, the same convention as the rest of the reporting. An invoice is flagged when it stands strictly above the three-quarter point by more than one and a half times the width of that middle half.
Task: Print how many invoices are flagged.
Input
The first line holds a single integer n, the number of invoices. Each of the next n lines holds one invoice amount, which may carry decimals.
Output
One line holding the number of flagged invoices, as a whole number. If nothing is flagged, print 0.
Example:
Input:
6
10
12
11
13
12
50
Output:
1
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