All problems

Hospital Triage

Hard · heap

A clinic has one waiting room and one doctor. You are given a list events describing what happens during the day, in order. Each event is a string in one of three forms:

Return a list with one entry for every "treat" event, in the order the events happen: the name of the patient who was called in, or "-" if the waiting room was empty.

A name can be used again after its owner has been treated or has left. The returning patient counts as a brand new arrival, with their own severity and their own place in the queue.

Examples

Example 1

Input: events = ["arrive ann 5", "arrive bo 9", "arrive cy 9", "treat", "treat", "treat", "treat"]

Output: ["bo", "cy", "ann", "-"]

bo and cy are both 9, and bo arrived first. ann goes last. The fourth treat finds an empty room.

Example 2

Input: events = ["arrive ann 4", "arrive bo 8", "leave bo", "leave dee", "treat"]

Output: ["ann"]

bo left before being treated, and dee was never waiting, so that event does nothing.

Example 3

Input: events = ["arrive ann 3", "arrive bo 3", "leave ann", "arrive ann 3", "treat", "treat"]

Output: ["bo", "ann"]

ann came back after leaving, so she is behind bo even though her first arrival was earlier.

Constraints