Find the first meeting pair that clashes given travel buffer
A field technician’s day planner lists visits like “09:00 to 10:30, Harbor Clinic”. Visits are in different buildings, so the planner also needs travel time between them. Before the day is published, the app must point at the first pair of visits the technician cannot make, so the dispatcher knows exactly what to move.
Implement findScheduleConflict(meetings, bufferMinutes). It returns the titles of the first conflicting pair, or null if the day works.
findScheduleConflict(meetings, bufferMinutes?) // => [string, string] | null
// meetings: Array<{ title: string, start: 'HH:MM', end: 'HH:MM' }>
'HH:MM' strings with exactly two digits each: hours 00 to 23 and minutes 00 to 59. '24:00' is also allowed, but only as an end (midnight at the end of the day).Error if any time is malformed (for example '9:00', '12:60', '25:00', or '24:00' as a start), or if a meeting’s end is not after its start.bufferMinutes (default 0) is the travel time needed between visits. Two visits fit if the later one starts at least bufferMinutes after the earlier one ends. With no buffer, back-to-back visits (10:00 end, 10:00 start) are fine.
[earlier.title, later.title] for the first pair that does not fit.Checking neighbours is enough: as long as no conflict has been found, every earlier meeting has already ended before the previous one started.
const day = [
{ title: 'Harbor Clinic', start: '09:00', end: '10:30' },
{ title: 'Mill Street Depot', start: '13:00', end: '14:00' },
{ title: 'North Library', start: '11:00', end: '12:15' },
];
findScheduleConflict(day); // => null
findScheduleConflict(day, 30); // => null (30 minutes before the library, 45 before the depot)
findScheduleConflict(day, 45); // => ['Harbor Clinic', 'North Library']
findScheduleConflict([
{ title: 'Standup', start: '09:30', end: '09:45' },
{ title: 'Install', start: '08:00', end: '10:00' },
{ title: 'Lunch', start: '12:00', end: '13:00' },
]);
// => ['Install', 'Standup']
findScheduleConflict([]); // => null
findScheduleConflict([{ title: 'Late', start: '23:00', end: '24:00' }]); // => null
findScheduleConflict([{ title: 'Oops', start: '9:00', end: '10:00' }]); // throws
Date. Convert times to minutes since midnight yourself.meetings or the meeting objects.