Waiting-time percentiles by hospital site
A health regulator reports the 50th, 90th and 99th percentile waiting times per hospital site, because averages hide long waits. Two files must be joined.
patients.csv:patient_id,department,arrival_hour,wait_mindepartments.csv:department,site(hospital name),beds
Task: line 1 of the input is a site name (exactly as in departments.csv), line 2 holds integer percentiles separated by spaces, for example 50 90. Pool the waits of all patients whose department belongs to that site and sort them. The percentile p uses linear interpolation: position pos = (n - 1) x p / 100, lo = floor(pos), hi = min(lo + 1, n - 1), value w[lo] + (w[hi] - w[lo]) x (pos - lo). Print Patients: n then one line Pp: value per requested percentile in the given order, value with 2 decimals (for example P90: 88.40). If the site has no patients print only No data.
Files your program can read
patient_id,department,arrival_hour,wait_min P3001,Dermatology,16,47 P3002,Orthopaedics,16,42 P3003,Cardiology,16,57 P3004,Paediatrics,12,38 P3005,Maternity,12,17 P3006,Oncology,15,11 P3007,Emergency,16,11 ...
department,site,beds Emergency,St Mary Central,12 Radiology,St Mary Central,17 Cardiology,St Mary Central,22 Orthopaedics,Riverside General,27 Paediatrics,Riverside General,32 Oncology,Riverside General,37 Dermatology,Kingsway Clinic,42 ...
Open them by name, for example open("patients.csv").
Sample test
Input
St Mary Central 50 90
Expected output
Patients: 100 P50: 46.50 P90: 103.00
Your answer is also checked against 4 hidden tests.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
