Problem · Array

Lab and Consultation Appointment Matching

Learn this problem
HardAssort Health logoAssort HealthFULLTIMEPHONE SCREEN

Problem statement

You receive parallel arrays describing raw provider availability. Record i contains providers[i], appointmentTypes[i], startTimes[i], and endTimes[i].

Validation and normalization

  • A valid provider is a non-empty string.
  • The appointment type must be LAB or CONSULTATION.
  • Each time must use the exact 24-hour form HH:MM.
  • The end time must be exactly 10 minutes after the start time on the same day.

Discard every invalid record. Treat duplicate valid records for the same provider and appointment type as one interval.

Building appointments

Group valid records by provider and appointment type, then merge consecutive 10-minute intervals. From each merged interval, generate every possible 30-minute appointment using a 10-minute start step.

Matching the journey

A complete journey consists of one LAB appointment followed by one CONSULTATION appointment. The consultation must start at or after the lab ends, and the waiting time must be at most 60 minutes.

Return every valid journey as:

[labProvider, labStart, labEnd, consultationProvider, consultationStart, consultationEnd]

Sort results by lab start time, lab provider, consultation start time, and consultation provider, all ascending.

Function

findAppointmentCombinations(providers: String[], appointmentTypes: String[], startTimes: String[], endTimes: String[]) → String[][]

Examples

Example 1

providers = ["lab-a","lab-a","lab-a","doctor-a","doctor-a","doctor-a","doctor-b","doctor-b","doctor-b"]appointmentTypes = ["LAB","LAB","LAB","CONSULTATION","CONSULTATION","CONSULTATION","CONSULTATION","CONSULTATION","CONSULTATION"]startTimes = ["09:00","09:10","09:20","10:00","10:10","10:20","10:20","10:30","10:40"]endTimes = ["09:10","09:20","09:30","10:10","10:20","10:30","10:30","10:40","10:50"]return = [["lab-a","09:00","09:30","doctor-a","10:00","10:30"],["lab-a","09:00","09:30","doctor-b","10:20","10:50"]]

The lab records form one 30-minute appointment. Both consultations start after it ends and have waits of 30 and 50 minutes.

Example 2

providers = ["lab","lab","lab","","doctor","doctor","doctor","bad"]appointmentTypes = ["LAB","LAB","LAB","LAB","CONSULTATION","CONSULTATION","CONSULTATION","CONSULTATION"]startTimes = ["08:00","08:10","08:20","08:30","09:00","09:10","09:20","9:30"]endTimes = ["08:10","08:20","08:30","08:40","09:10","09:20","09:30","09:40"]return = [["lab","08:00","08:30","doctor","09:00","09:30"]]

The empty provider and malformed 9:30 time are discarded. The remaining records form one lab and one consultation with a 30-minute wait.

Example 3

providers = ["lab","lab","lab","doctor","doctor","doctor"]appointmentTypes = ["LAB","LAB","LAB","CONSULTATION","CONSULTATION","CONSULTATION"]startTimes = ["10:00","10:10","10:20","11:40","11:50","12:00"]endTimes = ["10:10","10:20","10:30","11:50","12:00","12:10"]return = []

The consultation begins 70 minutes after the lab ends, exceeding the maximum wait.

Constraints

  • 0 <= providers.length <= 10^5.
  • All four input arrays have the same length.
  • Every input element is a non-null string; an empty string represents a missing field.
  • All valid intervals fall within one day and do not cross midnight.
  • The number of returned journeys fits in memory.
drafts saved locally
public String[][] findAppointmentCombinations(String[] providers, String[] appointmentTypes, String[] startTimes, String[] endTimes) {
  // write your code here
}
providers["lab-a","lab-a","lab-a","doctor-a","doctor-a","doctor-a","doctor-b","doctor-b","doctor-b"]
appointmentTypes["LAB","LAB","LAB","CONSULTATION","CONSULTATION","CONSULTATION","CONSULTATION","CONSULTATION","CONSULTATION"]
startTimes["09:00","09:10","09:20","10:00","10:10","10:20","10:20","10:30","10:40"]
endTimes["09:10","09:20","09:30","10:10","10:20","10:30","10:30","10:40","10:50"]
expected[["lab-a", "09:00", "09:30", "doctor-a", "10:00", "10:30"], ["lab-a", "09:00", "09:30", "doctor-b", "10:20", "10:50"]]
checking account