TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

Triage

Problem statement, definition, constraints, and public examples.

Problem Statement

PROBLEM STATEMENT

As the triage nurse in a hospital's emergency room, you have a duty to admit
patients first in order of problem severity, and then in order of when they
came in.  You are given a String[] of patients to admit.  The Strings will be
formatted as follows:

"TIME:NAME,PRIORITY"

Where time is the time the patient came in (in minutes), name is a string name
of the patient, and priority is the integer priority.  The higher the integer,
the higher the priority.  The higher a patient's priority, the sooner she needs
to be seen by a doctor.  Write a function admitPatients which will take in this
String[] and the frequency (in minutes) in which there are openings, and return
a String[] of who is admitted at each frequency interval.  If no patient is in
the waiting room at a given interval, place an empty String for that interval.
When a patient walks into an empty waiting room, she must still wait for the
next interval, regardless of whether or not someone was let in the last time
around.

If a patient arrives in the waiting room when a interval starts, she has to
spend time registering and waits until the next interval, even if the waiting
room was empty.

Patients are chosen as follows:
*The patient with the highest priority in the waiting room who is already
registered (see above).
*If two or more patients have the same highest priority, choose patients in the
order they arrived (the ordering of the String[] represents the order in which
patients arrive).

DEFINITION

Class name: Triage
Method name: admitPatients
Parameters: String[], int
Returns: String[]
The method signature is:
String[] admitPatients(String[] patients, int frequency)
Be sure your method is public.

TopCoder will ensure the validity of the inputs.  Inputs are valid if all of
the following criteria are met:
*patients contains between 1 and 20 elements, inclusive
*each element of patients will be a String formatted as "TIME:NAME,PRIORITY"
*name may contain characters [a-z] and [A-Z]
*time will be from 0 to 100, inclusive
*priority will be from 0 to 10, inclusive
*frequency will be from 5 to 10, inclusive
*each name will be unique (Alex and aLex are to be treated as two unique names)

The first interval is at time = frequency.  Do not place an element in the
return String[] at time = 0.  See examples to clarify.
The function should return when all patients have been admitted.

EXAMPLES
patients =
{"0:Alex,0",
 "3:Bob,0",
 "6:Tim,0",
 "9:Greg,1"
}
frequency = 5

First frequency = 5:
Alex is admitted.
frequency = 10:
Greg is admitted, since his priority was higher.
frequency = 15:
Bob is admitted.
frequency = 20:
Tim is admitted.

return = {"Alex","Greg","Bob","Tim"}

patients =
{"3:Albert,0",
 "4:Bobby,5",
 "5:Charlene,4",
 "8:Darren,4",
 "16:Eric,0",
 "40:Frances,0"
}
frequency = 6

return = {"Bobby","Charlene","Darren","Albert","Eric","","Frances"}

patients =
{"48:Tony,8",
 "49:Helen,0",
 "50:Madeline,9"
}
frequency = 10

return = {"","","","","Tony","Madeline","Helen"}

Definition

Class:
Triage
Method:
admitPatients
Parameters:
String[], int
Returns:
String[]
Method signature:
String[] admitPatients(String[] param0, int param1)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems