Triage board
MediumOnline Assessment
Order the patients on a clinic's waiting board so the nurse can see who to call next.
Each patient is a string "name|severity|age|HH:MM": the severity is an integer from 1 (minor) to 5 (critical), and HH:MM is the arrival time on a 24-hour clock. All patients arrived today, at or before now.
The board is ordered by these rules, each applied only when all the earlier ones tie:
- Effective severity, highest first. It is the written severity, plus a bonus for long waits, never above 5. The bonus is
+1once the patient has waited at least 90 minutes and+2once they have waited at least 180 minutes (the wait isnowminus the arrival time). - Priority patients first: children aged 12 or younger and adults aged 70 or older.
- Earlier arrival first.
- Name in ascending order by character code (uppercase letters come before lowercase ones). Patients who still tie keep their original order in the list.
Input: patients, a list of strings in the format above, and now, a string "HH:MM".
Output: the patients' names in board order, as a list of strings. If there are no patients, return [].
Example 1
- Input:
- [["Ann|2|40|09:00","Bo|4|35|09:30","Cy|2|9|09:45","Di|4|50|09:10"],"10:00"]
- Output:
- ["Di","Bo","Cy","Ann"]
- Explanation
- Nobody has waited 90 minutes at 10:00, so severities stay as written. Severity 4: Di arrived before Bo. Severity 2: Cy is a child, so Cy comes before Ann even though Ann arrived earlier.
Example 2
- Input:
- [["Eli|2|30|10:30","Fay|3|45|11:30","Gus|1|80|08:30","Hal|5|20|10:00","Ivy|4|20|10:00"],"12:00"]
- Output:
- ["Hal","Ivy","Gus","Eli","Fay"]
- Explanation
- At 12:00 Eli has waited exactly 90 minutes (+1, to 3), Gus 210 (+2, to 3), and Hal and Ivy 120 (+1, both reach 5 and the bonus is capped). Hal and Ivy tie on everything but name. Among the 3s, Gus is 80 years old and goes first, then Eli by arrival time, then Fay.
Example 3
- Input:
- [["Jo|3|12|08:00","Kim|3|13|08:00","Lou|3|70|08:00","Max|3|69|08:00","Ned|2|40|07:31","Oz|2|40|07:30"],"09:00"]
- Output:
- ["Jo","Lou","Oz","Kim","Max","Ned"]
- Explanation
- Ned has waited 89 minutes and keeps severity 2; Oz has waited exactly 90 and rises to 3. Among the severity-3 patients, Jo (age 12) and Lou (age 70) are priority patients, Jo before Lou by name. Kim (13) and Max (69) are not priority patients, so they come after Oz, who arrived earlier.
Constraints
0 <= patients.length <= 300nowand every arrival time are valid times between00:00and23:59, and no arrival is later thannow1 <= severity <= 5,0 <= age <= 120; names have no|