Lab and Consultation Appointment Matching
Updated
Problem statement
Given provider availability records, return every journey made of one LAB appointment followed by one CONSULTATION appointment, using the rules below. Record i is providers[i], appointmentTypes[i], startTimes[i] and endTimes[i].
A record is valid only if all of these hold. Discard every invalid record.
- The provider is a non-empty string.
- The appointment type is
LABorCONSULTATION. - Each time uses the exact 24-hour form
HH:MM. - The end time is exactly
10minutes after the start time on the same day.
Duplicate valid records for the same provider and appointment type count as one interval. For each provider and appointment type, merge back-to-back 10-minute intervals into blocks. Each block gives every 30-minute appointment that fits inside it, with starts 10 minutes apart beginning at the block start.
In a journey, the consultation starts at or after the lab ends, and the wait between them is at most 60 minutes. Return each journey as:
[labProvider, labStart, labEnd, consultationProvider, consultationStart, consultationEnd]Sort the journeys by lab start time, then lab provider, then consultation start time, then 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.
Similar questions at other companies
- Merchant Capacity Interval MergeDoorDash · PHONE SCREENDoorDash interview questions
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Process Shopping Records, Promotions, and Display OrderInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Detect Security Attacks from Network LogsFireworks AI · PHONE SCREEN
- Merge Collinear Point SegmentsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Maximum Profit in Job SchedulingAmazon · PHONE SCREEN
- Smallest Range Covering Elements from K ListsSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Popular and Instant-Runoff Election WinnersCoursera · PHONE SCREEN
- The Skyline ProblemGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions