Problem · Array

Hospital Triage Priority

Learn this problem
EasyGoldman Sachs logoGoldman SachsFULLTIMEPHONE SCREEN

Problem statement

Patient i arrives at index i with severity severities[i]. Return the 1-based treatment position of patient k.

  • Greater severity is treated first.
  • If genders is empty, equal-severity patients are ordered by earlier arrival.
  • Otherwise genders.length == severities.length; at equal severity, F is treated before M, then earlier arrival breaks the remaining tie.

Function

treatmentOrder(severities: int[], genders: String, k: int) → int

Examples

Example 1

severities = [3,1,4,4,2]genders = ""k = 2return = 1

Patient 2 is the earlier of the two severity-4 patients.

Example 2

severities = [3,1,4,4,2]genders = "MFMFM"k = 2return = 2

Patient 3 is female and therefore precedes patient 2 at equal severity.

Constraints

  • 1 <= severities.length <= 100000
  • 1 <= severities[i] <= 10^9
  • 0 <= k < severities.length
  • genders is empty or has the same length as severities and contains only M and F.

More Goldman Sachs problems

drafts saved locally
public int treatmentOrder(int[] severities, String genders, int k) {
  // write your code here
}
severities[3,1,4,4,2]
genders""
k2
expected1
checking account